我正在尝试获取我的 nuxtjs 应用程序的先前路线,因此我使用了beforeRouteEnter,但beforeRouteEnter没有触发。
我尝试在 nuxt-link 中添加密钥: 但仍然不起作用..
<nuxt-link :key="$route.path" :to="'/services/'+service.id">
Run Code Online (Sandbox Code Playgroud)
所以这是我的代码:
created: function(){
console.log("created");
},
mounted: function(){
console.log("mounted");
},
mounted: function(){
console.log("mounted");
},
beforeRouteEnter(to, from, next) {
console.log("before route called");
next(vm => {
console.log("prev rout is: "+vm.prevRoute);
})
}
Run Code Online (Sandbox Code Playgroud)
我期望 :
before route called
prev rout is: /services
created
mounted
Run Code Online (Sandbox Code Playgroud)
但我只得到:
created
mounted
Run Code Online (Sandbox Code Playgroud)
我做错了什么吗?
在我当前基于 nuxt \xcb\x862.0.0 的项目中尝试您的代码,在从 / 路线导航到 /_slug 路线后,我向您报告我的开发工具控制台。
\n\n_slug.js:200 before route called\n_slug.js:192 created\n_slug.js:198 mounted\n_slug.js:205 prev rout is: undefined\nRun Code Online (Sandbox Code Playgroud)\n\n当我刷新页面时 _slug 是相同的。
\n\n如果你想要以前的路线为什么不简单地这样做:
\n\nbeforeRouteEnter(to, from, next) {\n console.log("before route called");\n const previousRoute = from.path || from.fullPath\n console.log(`Previous Route ${previousRoute}`)\n}\nRun Code Online (Sandbox Code Playgroud)\n\n哪个日志是:
\n\n_slug.js:200 before route called\n_slug.js:202 Previous Route /\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
21792 次 |
| 最近记录: |