How to set a default route in vuepress when no page exists

103 Views Asked by At

I'm using Vuepress 1.5. I was wondering if there is a way to redirect users back to the root path (/) if they navigate to a route that does not exist e.g. /some-unknow-path/new

The default setting for VuePress seems to be to display the 404 page, however, I would prefer to just redirect them to the root path

1

There are 1 best solutions below

0
Anthony Phan On

Turns out the way to do this is to add a default route into the `enhanceApp.js' file as shown below.

export default ({
  Vue, // the version of Vue being used in the VuePress app
  options, // the options for the root Vue instance
  router, // the router instance for the app
  siteData // site metadata
}) => {
  // ...apply enhancements for the site.
  router.addRoute({ path: '/*', redirect: '/' })
}