Skip to content

Commit 6fc435a

Browse files
committed
chore: tweaks
1 parent d43d3b6 commit 6fc435a

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

packages/@vuepress/core/lib/app/app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import appEnhancers from '@internal/app-enhancers'
88
import globalUIComponents from '@internal/global-ui'
99
import ClientComputedMixin from '@transform/ClientComputedMixin'
1010
import VuePress from './plugins/VuePress'
11-
import handleRedirect from './redirect.js'
11+
import { handleRedirectForCleanUrls } from './redirect.js'
1212

1313
// built-in components
1414
import Content from './components/Content.js'
@@ -75,7 +75,7 @@ export function createApp (isServer) {
7575
}
7676
})
7777

78-
handleRedirect(router)
78+
handleRedirectForCleanUrls(router)
7979

8080
const options = {}
8181

packages/@vuepress/core/lib/app/redirect.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// - `/foo.html` means your source file is `/foo.md`
55
//
66
// 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
88
// default theme. so we can't easily modify `/foo.html` directly
99
// to `/foo` (i.e. remove html suffix)
1010
//
@@ -17,15 +17,14 @@
1717
//
1818
// For unknown request `/foo/`
1919
// - redirect to `/foo.html` if it exists
20+
//
21+
// If all the above redirect rules don't exist, you'll get a 404
2022

21-
export default function handleRedirect (router) {
23+
export function handleRedirectForCleanUrls (router) {
2224
router.beforeEach((to, from, next) => {
2325
if (isRouteExists(router, to.path)) {
2426
next()
2527
} else {
26-
// For unknown request `/foo`
27-
// redirect to /foo/ if exists
28-
// redirect to /foo.html if exists
2928
if (!/(\/|\.html)$/.test(to.path)) {
3029
const endingSlashUrl = to.path + '/'
3130
const endingHtmlUrl = to.path + '.html'
@@ -36,8 +35,6 @@ export default function handleRedirect (router) {
3635
} else {
3736
next()
3837
}
39-
// For unknown request `/foo/`
40-
// redirect to /foo.html if exists
4138
} else if (/\/$/.test(to.path)) {
4239
const endingHtmlUrl = to.path.replace(/\/$/, '') + '.html'
4340
if (isRouteExists(router, endingHtmlUrl)) {

0 commit comments

Comments
 (0)