Home

Issue: 1843

How to redirect with vue-router?

[issue link]

So i have a SPA where the base path has to redirect to a locale folder. Normally i would do this by defining two paths that are pointing to the same page in the router:

  routes: [
    {
      path: '/',
      redirect: { name: 'index' }
    },
    {
      path: '/en/',
      name: 'index',
      component: index
    }
  ]

E.g. http://test.com/ is redirected to http://test.com/en.

Following solved the issue, but i am not sure if this is best-practice?

<script>
export default {
  fetch ({ params, redirect }) {
    redirect(301, '/en')
  }
}
</script>
This question is available on Nuxt.js community (#c1656)