declaration of beforeRouteEnter(to,from,next) hook should be updated
See original GitHub issueVersion
3.0.1
Reproduction link
https://jsfiddle.net/doommm/50wL7mdz/74369/
Steps to reproduce
- Vue 2.5.3
- Vue-class-component 6.1.0
- Typescript 2.6.1
- vscode 1.17.2, vetur 0.11.0
I found that in declaration file(types/router.d.ts
), there’s a type named NavigationGuard
used for beforeRouteEnter
and other two hooks. The function declaration of next
is ((vm: Vue) => any) | void) => void
, and should it be updated so we could access all members declared in class(or object)?
I wrote three examples to explain my confusion.
- In .vue file with object literal style, i cant access my own properties.
- In .vue file with
vue-class-component
, if i add an type identifier manually, it works. no error. if not, error. - In separate .ts file with
vue-class-component
, whether i add identifier or not, got error. But if i roll back to typescript 2.5.3, and add type identifier, it works.
I think the declaration should be updated(Generics? T extends Vue
or ?), but i’m not sure about that. Sorry for my poor english If I dont describe the problem clearly.
What is expected?
all class(object) members should be accessed in vm.propertyName
What is actually happening?
We could only access members of Vue.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Additional Hooks
registerHooks allows you to register such hooks: ... hooks beforeRouteEnter(to, from, next) { console.log('beforeRouteEnter') next() } beforeRouteUpdate(to, ...
Read more >Vue Router with vue-class-component: next function does ...
Please move your beforeRouteEnter hook to @Component decorator. @Component({ template: '<div></div>', beforeRouteEnter(to, from, next){ ...
Read more >Navigation Guards | Vue Router
Navigation confirmed. Call global afterEach hooks. DOM updates triggered. Call callbacks passed to next in beforeRouteEnter guards with instantiated instances.
Read more >Vue.js
The way we determine the async-ness of these hooks is convoluted. ... I imagine that after replacing routes router would check if current...
Read more >How To Do More With Vue Router
After installing Axios, we can update our Home.vue to look like this: ... beforeRouteEnter(to, from, next) { axios ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m still confused. There must be something i misunderstood or even never know.
I’m focusing on the In-Component guards
beforeRouteEnter(to,from,next)
, and they(In-Component guards) should be tightly coupled with the component(or should be reusable?).So for the example you posted, do you mean to define
beforeRouteEnter
inBlog
? Shouldn’t it become(vm: Blog) => any
?@websmurf, @webrsb Please try this:
This is using an “user-defined type guard” for narrowing.