如何在 nuxt.js 中处理路由参数更新

How to handle route param updates in nuxt.js

如果目的地与当前路线相同并且只有参数在变化

going from one profile to another /users/1 -> /users/2.

如何识别并更新组件?

我不确定 next.js 是否相同,但在适当的路由器中,即使参数更改,也会重复使用相同的组件。因此,您需要专门 watch 更改参数。

来自 Vue 路由器文档:

One thing to note when using routes with params is that when the user navigates from /user/foo to /user/bar, the same component instance will be reused. Since both routes render the same component, this is more efficient than destroying the old instance and then creating a new one. However, this also means that the lifecycle hooks of the component will not be called.

看这里:https://router.vuejs.org/en/essentials/dynamic-matching.html#reacting-to-params-changes