rafgraph / spa-github-pages

Host single page apps with GitHub Pages
https://spa-github-pages.rafgraph.dev
MIT License
3.83k stars 565 forks source link

Getting infinite redirect? #69

Open CWSites opened 2 months ago

CWSites commented 2 months ago

I'm running into some weird behavior, if I click on a link which goes to /privacy-policy then the SPA redirects fine. However if I try to go directly to /privacy-policy I get stuck in a redirect loop.

https://mydomain.com/privacy-policy/?p=/&q=p=/~and~q=p=/~and~q=p=/~and~q=p=/~and~q=p=/~and~q=p=/~and~q=p=/

I'm using the code from the repo... what am I doing wrong?

var pathSegmentsToKeep = 1;

var l = window.location;
l.replace(
  l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
  l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
  l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
  (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
  l.hash
);
GreeningSiren commented 2 months ago

On a custom domain, pathSegmentsToKeep should be 0 instead of 1