Vue-router: Props on router-view and beforeRouteEnter

Created on 21 Dec 2016  路  4Comments  路  Source: vuejs/vue-router

Hello,
I figured out that we can pass data to a view component using props on RouterView.

<router-view :foo="bar"></router-view>

I dont know if it s supposed to works like this it s working.

I would like to be able to use those data in beforeRouteEnter to prefetch some data related to this props.
But it dont seams to be possible to use the props data in beforeRouteEnter.
Maybe you can add this feature ?

All 4 comments

You already can:

beforeRouteEnter (to, from, next) {
  next(vm => {
    // access to component instance via `vm`
  })
}

(http://router.vuejs.org/en/advanced/navigation-guards.html#in-component-guards)

Yes, i know i can do that. But it s not what i want to do.
I need a props data to fetch something else so i cant do it in the next.

You can fetch _something else_ with the hook.
You can also use a global state management lib like vuex
If you got more questions, please, ask them on the forum or StackOverflow

I dont want to do it in the hook because i want do it before the route enter

Was this page helpful?
0 / 5 - 0 ratings