4
4
// - `/foo.html` means your source file is `/foo.md`
5
5
//
6
6
// The original design of VuePress relied on above two styles
7
- // of routing, especially the routing calculations involved in
7
+ // of routing, especially the calculation involved of routes at
8
8
// default theme. so we can't easily modify `/foo.html` directly
9
9
// to `/foo` (i.e. remove html suffix)
10
10
//
17
17
//
18
18
// For unknown request `/foo/`
19
19
// - redirect to `/foo.html` if it exists
20
+ //
21
+ // If all the above redirect rules don't exist, you'll get a 404
20
22
21
- export default function handleRedirect ( router ) {
23
+ export function handleRedirectForCleanUrls ( router ) {
22
24
router . beforeEach ( ( to , from , next ) => {
23
25
if ( isRouteExists ( router , to . path ) ) {
24
26
next ( )
25
27
} else {
26
- // For unknown request `/foo`
27
- // redirect to /foo/ if exists
28
- // redirect to /foo.html if exists
29
28
if ( ! / ( \/ | \. h t m l ) $ / . test ( to . path ) ) {
30
29
const endingSlashUrl = to . path + '/'
31
30
const endingHtmlUrl = to . path + '.html'
@@ -36,8 +35,6 @@ export default function handleRedirect (router) {
36
35
} else {
37
36
next ( )
38
37
}
39
- // For unknown request `/foo/`
40
- // redirect to /foo.html if exists
41
38
} else if ( / \/ $ / . test ( to . path ) ) {
42
39
const endingHtmlUrl = to . path . replace ( / \/ $ / , '' ) + '.html'
43
40
if ( isRouteExists ( router , endingHtmlUrl ) ) {
0 commit comments