Skip to content

Commit

Permalink
chore: tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Feb 8, 2019
1 parent d43d3b6 commit c94bebf
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/@vuepress/core/lib/app/redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// - `/foo.html` means your source file is `/foo.md`
//
// The original design of VuePress relied on above two styles
// of routing, especially the routing calculations involved in
// of routing, especially the calculation involved of routes at
// default theme. so we can't easily modify `/foo.html` directly
// to `/foo` (i.e. remove html suffix)
//
Expand All @@ -17,15 +17,14 @@
//
// For unknown request `/foo/`
// - redirect to `/foo.html` if it exists
//
// If all the above redirect rules don't exist, you'll get a 404

export default function handleRedirect (router) {
router.beforeEach((to, from, next) => {
if (isRouteExists(router, to.path)) {
next()
} else {
// For unknown request `/foo`
// redirect to /foo/ if exists
// redirect to /foo.html if exists
if (!/(\/|\.html)$/.test(to.path)) {
const endingSlashUrl = to.path + '/'
const endingHtmlUrl = to.path + '.html'
Expand All @@ -36,8 +35,6 @@ export default function handleRedirect (router) {
} else {
next()
}
// For unknown request `/foo/`
// redirect to /foo.html if exists
} else if (/\/$/.test(to.path)) {
const endingHtmlUrl = to.path.replace(/\/$/, '') + '.html'
if (isRouteExists(router, endingHtmlUrl)) {
Expand Down

0 comments on commit c94bebf

Please sign in to comment.