Answer the question
In order to leave comments, you need to log in
How to pass data to vue-router route?
I have a set of routes:
/foo
/bar
/baz
...
When the application is initialized, when any of these routes are requested, it redirects to the /i-love-vue-js
. in the component that renders this route, some processes take place, after which, a redirect to the original route occurs. When redirecting to /i-love-vue-js
me, I need to transfer data to this route. The question is how to do it? I know that you can use query, but then this data will be visible in the address bar, and I would like to avoid this. the redirect goes like this:
router.beforeEach((to, from, next) => {
if(true) {
next({
path: '/i-love-vue-js',
query: data
})
}
next()
})
Answer the question
In order to leave comments, you need to log in
Give the route a name and pass the data as params:
next({
name: 'здесь имя маршрута, придумайте сами',
params: data,
})
this.$route.params
. If you want the params properties to be passed to the component's parameters, also add . props: true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question