7

Is there any way to update Vue-router routes programmatically without reloading the page?

I'm loading different route paths based on the language that is selected, e.g.:

{ path: '/' + i18n.t('url_welcome'), name: 'welcome, component: Welcome },

Unfortunately, route paths don't update automatically when the language is changed.

butaminas
  • 672
  • 7
  • 23
  • Do you mean [dynamic route matching](https://router.vuejs.org/guide/essentials/dynamic-matching.html) like `{ path: '/:language', name: 'welcome', component: Welcome }` – vahdet Jan 28 '20 at 13:33

1 Answers1

6

Adding Routes

Dynamic routing is achieved mainly via two functions: router.addRoute() and router.removeRoute().

https://router.vuejs.org/guide/advanced/dynamic-routing.html#adding-routes

artoju
  • 1,612
  • 12
  • 12
  • Is there a way I could just reload the routes? What I'm trying to achieve is that one set of routes would be available for the currently selected language only and when you change the language, you shouldn't be able to use the routes from the previous language. – butaminas Jan 28 '20 at 13:42
  • There is no way to delete routes currently. Reloading the page may be your only option. – artoju Jan 28 '20 at 13:52
  • 2
    The new doc is here: https://router.vuejs.org/guide/advanced/dynamic-routing.html#adding-routes – Jean Claveau Jul 09 '22 at 14:06