vue路由器同页刷新

you*_*nam 2 vue.js vue-router vuejs2

我想从以下 URL http://localhost:8081/#/scenarios/SCNRF3SZ2FS54E66B456转到此 URL http://localhost:8081/#/scenarios/SCNRF3XAPLPJ241807A9。但它不起作用,代码如下:

export default new Router({
   mode: 'hash',
   linkActiveClass: 'open active',
   scrollBehavior: () => ({ y: 0 }),
   routes: [
     {
       path: '/',
       redirect: '/scenarios/:id',
       component: Full,
       beforeEnter: beforeEnter,
       children: [{
       path: '/scenarios/:id',
       name: 'Scenario',
       component: Scenario
     }]
   }
  ]
 })
Run Code Online (Sandbox Code Playgroud)

我该如何让它发挥作用?

ret*_*ade 5

如果我正确理解您的问题,那么当 id 更改时,您的路线不会使用新数据进行更新。

要解决这个问题,您可以观察路由的更改或将其合并到 beforeRouteUpdate 挂钩中,路由器文档对此做了很好的解释:

https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes