vue-router

get route params in asyncData after router push

两盒软妹~` 提交于 2021-01-03 06:57:55
问题 I'm trying to get the route params in the asyncData method, it works if I go manually to the route, but if I use router Push method, it doesn't get any params. this is my asynData method: async asyncData(ctx) { const { id } = ctx.app.router.currentRoute.params await ctx.store.dispatch('user/GET_USER', id) return { user: ctx.store.state.user.user } }, and this is how I navigate to the respective page: goToEdit(id) { this.$router.push({ path: `/users/${id}/edit` }) } 回答1: You need to get route

get route params in asyncData after router push

蓝咒 提交于 2021-01-03 06:57:42
问题 I'm trying to get the route params in the asyncData method, it works if I go manually to the route, but if I use router Push method, it doesn't get any params. this is my asynData method: async asyncData(ctx) { const { id } = ctx.app.router.currentRoute.params await ctx.store.dispatch('user/GET_USER', id) return { user: ctx.store.state.user.user } }, and this is how I navigate to the respective page: goToEdit(id) { this.$router.push({ path: `/users/${id}/edit` }) } 回答1: You need to get route

get route params in asyncData after router push

断了今生、忘了曾经 提交于 2021-01-03 06:57:29
问题 I'm trying to get the route params in the asyncData method, it works if I go manually to the route, but if I use router Push method, it doesn't get any params. this is my asynData method: async asyncData(ctx) { const { id } = ctx.app.router.currentRoute.params await ctx.store.dispatch('user/GET_USER', id) return { user: ctx.store.state.user.user } }, and this is how I navigate to the respective page: goToEdit(id) { this.$router.push({ path: `/users/${id}/edit` }) } 回答1: You need to get route

Vue Router - Change anchor in route on scroll

谁说胖子不能爱 提交于 2020-12-30 12:46:21
问题 I am basically trying to have the exact same routing behaviour on my site as here: https://router.vuejs.org/guide/#html. Notice when you scroll down the link changes to https://router.vuejs.org/guide/#javascript. Scroll back up and it is vice versa. When reloading the page your position gets saved. I added the following scroll behavior to my router: scrollBehavior(to, from, savedPosition) { if (to.hash) { return { selector: to.hash } } else if (savedPosition) { return savedPosition; } else {

Vue Router - Change anchor in route on scroll

╄→尐↘猪︶ㄣ 提交于 2020-12-30 12:45:43
问题 I am basically trying to have the exact same routing behaviour on my site as here: https://router.vuejs.org/guide/#html. Notice when you scroll down the link changes to https://router.vuejs.org/guide/#javascript. Scroll back up and it is vice versa. When reloading the page your position gets saved. I added the following scroll behavior to my router: scrollBehavior(to, from, savedPosition) { if (to.hash) { return { selector: to.hash } } else if (savedPosition) { return savedPosition; } else {

Vue Router - Change anchor in route on scroll

牧云@^-^@ 提交于 2020-12-30 12:43:24
问题 I am basically trying to have the exact same routing behaviour on my site as here: https://router.vuejs.org/guide/#html. Notice when you scroll down the link changes to https://router.vuejs.org/guide/#javascript. Scroll back up and it is vice versa. When reloading the page your position gets saved. I added the following scroll behavior to my router: scrollBehavior(to, from, savedPosition) { if (to.hash) { return { selector: to.hash } } else if (savedPosition) { return savedPosition; } else {

Vue Router - Change anchor in route on scroll

最后都变了- 提交于 2020-12-30 12:40:41
问题 I am basically trying to have the exact same routing behaviour on my site as here: https://router.vuejs.org/guide/#html. Notice when you scroll down the link changes to https://router.vuejs.org/guide/#javascript. Scroll back up and it is vice versa. When reloading the page your position gets saved. I added the following scroll behavior to my router: scrollBehavior(to, from, savedPosition) { if (to.hash) { return { selector: to.hash } } else if (savedPosition) { return savedPosition; } else {

Redirecting twice in a single Vue navigation

偶尔善良 提交于 2020-12-30 06:11:16
问题 In my Vue app, a user's homepage depends on their role. To ensure that a user is shown the correct homepage, I use this navigation guard: export default (to, from, next) => { const authService = getAuthService() if (to.path === '/') { // if they've requested the home page, send them to // different pages depending on their role if (authService.isUser()) { next({ name: 'events' }) } else if (authService.isAdmin()) { next({ name: 'admin-events' }) } else { next() } } } Then when a user

Redirecting twice in a single Vue navigation

一个人想着一个人 提交于 2020-12-30 06:01:48
问题 In my Vue app, a user's homepage depends on their role. To ensure that a user is shown the correct homepage, I use this navigation guard: export default (to, from, next) => { const authService = getAuthService() if (to.path === '/') { // if they've requested the home page, send them to // different pages depending on their role if (authService.isUser()) { next({ name: 'events' }) } else if (authService.isAdmin()) { next({ name: 'admin-events' }) } else { next() } } } Then when a user

Redirecting twice in a single Vue navigation

天大地大妈咪最大 提交于 2020-12-30 06:01:06
问题 In my Vue app, a user's homepage depends on their role. To ensure that a user is shown the correct homepage, I use this navigation guard: export default (to, from, next) => { const authService = getAuthService() if (to.path === '/') { // if they've requested the home page, send them to // different pages depending on their role if (authService.isUser()) { next({ name: 'events' }) } else if (authService.isAdmin()) { next({ name: 'admin-events' }) } else { next() } } } Then when a user