Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue-router alias with fixed param

I have this little router over here, and basically I want to have a default language for my site. This means that the same content should be seen if you access www.example.com/about and www.example.com/es/about

I thought an alias would be apropiate for this, however I'm getting a error when tryin to access /about.

[vue-router] missing param for aliased route with path "/:language/about": Expected "language" to be defined

This makes sense as the :language param is not set, is there any way I can implement what I want? Can I set a fixed :language param whenever the user hits the alias?

This is my router.

router = new Router({
  routes: [
    {
      path: '/:language/about',
      alias: '/about'
      component: About
    }
  ]
})
like image 229
Borjante Avatar asked Dec 01 '17 16:12

Borjante


1 Answers

Using optional parameters (append ?) will solve this. You won't even need the alias:

router = new Router({
  routes: [
    {
      path: '/:language?/about',
      component: About
    }
  ]
})
like image 162
David Mold Avatar answered Oct 10 '22 19:10

David Mold