@@ -4,33 +4,37 @@ <h1>Page not found</h1>
44 < p > < strong > The page you are looking for does not exist</ strong > (Error 404)</ p >
55</ div >
66< script >
7- // Get the current path
8- const path = window . location . pathname ;
7+ function tryToRedirect ( ) {
8+ // Get the current path
9+ const path = window . location . pathname ;
910
10- // Transform the path: lowercase the first letter of each segment
11- const pathLowSegments = path
12- . split ( '/' )
13- . map ( segment => segment ? segment [ 0 ] . toLowerCase ( ) + segment . slice ( 1 ) : '' )
14- . join ( '/' ) ;
11+ // Transform the path: lowercase the first letter of each segment
12+ const pathLowSegments = path
13+ . split ( '/' )
14+ . map ( segment => segment ? segment [ 0 ] . toLowerCase ( ) + segment . slice ( 1 ) : '' )
15+ . join ( '/' ) ;
1516
16- // Redirect only if the transformed path is different from the current path
17- if ( pathLowSegments !== path ) {
18- window . location . replace ( pathLowSegments ) ;
19- return ;
20- }
17+ // Redirect only if the transformed path is different from the current path
18+ if ( pathLowSegments !== path ) {
19+ window . location . replace ( pathLowSegments ) ;
20+ return ;
21+ }
22+
23+ // Redirect element/* to /*
24+ if ( path . startsWith ( '/element/' ) ) {
25+ const elementPath = path . slice ( '/element/' . length ) ;
26+ if ( elementPath === 'index.html' ) {
27+ return ;
28+ }
2129
22- // Redirect element/* to /*
23- if ( path . startsWith ( '/element/' ) ) {
24- const elementPath = path . slice ( '/element/' . length ) ;
25- if ( elementPath === 'index.html' ) {
30+ window . location . replace ( '/' + elementPath ) ;
2631 return ;
2732 }
2833
29- window . location . replace ( '/' + elementPath ) ;
30- return ;
34+ // Show the 'not-found' element if no redirect is needed
35+ document . getElementById ( 'pathname' ) . textContent = path ;
36+ document . getElementById ( 'not-found' ) . style . display = 'block' ;
3137 }
3238
33- // Show the 'not-found' element if no redirect is needed
34- document . getElementById ( 'pathname' ) . textContent = path ;
35- document . getElementById ( 'not-found' ) . style . display = 'block' ;
39+ tryToRedirect ( ) ;
3640</ script >
0 commit comments