File tree 2 files changed +19
-9
lines changed
2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -8,17 +8,29 @@ <h1>Page not found</h1>
8
8
const path = window . location . pathname ;
9
9
10
10
// Transform the path: lowercase the first letter of each segment
11
- const newPath = path
11
+ const pathLowSegments = path
12
12
. split ( '/' )
13
13
. map ( segment => segment ? segment [ 0 ] . toLowerCase ( ) + segment . slice ( 1 ) : '' )
14
14
. join ( '/' ) ;
15
15
16
16
// Redirect only if the transformed path is different from the current path
17
- if ( newPath !== path ) {
18
- window . location . replace ( newPath ) ;
19
- } else {
20
- // Show the 'not-found' element if no redirect is needed
21
- document . getElementById ( 'pathname' ) . textContent = path ;
22
- document . getElementById ( 'not-found' ) . style . display = 'block' ;
17
+ if ( pathLowSegments !== path ) {
18
+ window . location . replace ( pathLowSegments ) ;
19
+ return ;
23
20
}
21
+
22
+ // Redirect element/* to /*
23
+ if ( path . startsWith ( '/element/' ) ) {
24
+ const elementPath = path . slice ( '/element/' . length ) ;
25
+ if ( elementPath === 'index.html' ) {
26
+ return ;
27
+ }
28
+
29
+ window . location . replace ( '/' + elementPath ) ;
30
+ return ;
31
+ }
32
+
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' ;
24
36
</ script >
Original file line number Diff line number Diff line change 1
1
/wiki/ /
2
2
/wiki/* /:splat
3
-
4
- /element/* /:splat
You can’t perform that action at this time.
0 commit comments