File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626( ( ) => {
2727 const pathSegmentsToKeep = 0 ;
2828 let l = new URL ( window . location ) ;
29- l . pathname = '/' + l . pathname . split ( '/' ) . slice ( 1 , 1 + pathSegmentsToKeep ) . join ( '/' ) + '/?/' +
30- l . pathname . slice ( 1 ) . split ( '/' ) . slice ( pathSegmentsToKeep ) . join ( '/' ) . replace ( / & / g, '~and~' ) ;
31- l . search = l . search ? '&' + l . search . slice ( 1 ) . replace ( / & / g, '~and~' ) : '' ;
32- window . SPA404Redirect = l ;
33- window . location . replace ( l . href ) ;
29+
30+ // Check if the URL is already in redirect format to prevent looping
31+ if ( ! l . search . startsWith ( '?/' ) ) {
32+ const basePath = '/' + l . pathname . split ( '/' ) . slice ( 1 , 1 + pathSegmentsToKeep ) . join ( '/' ) ;
33+ const restPath = l . pathname . slice ( 1 ) . split ( '/' ) . slice ( pathSegmentsToKeep ) . join ( '/' ) ;
34+ const newPath = basePath + ( basePath . endsWith ( '/' ) ? '' : '/' ) + '?/' + restPath . replace ( / & / g, '~and~' ) ;
35+ const newSearch = l . search ? '&' + l . search . slice ( 1 ) . replace ( / & / g, '~and~' ) : '' ;
36+
37+ l . pathname = newPath ;
38+ l . search = newSearch ;
39+
40+ window . SPA404Redirect = l ;
41+ window . location . replace ( l . href ) ;
42+ }
3443} ) ( ) ;
3544</ script > </ head > < body > </ body > </ html >
You can’t perform that action at this time.
0 commit comments