1. The problem arises:
When in use router-view
, if you jump between the same routes, it will be used by default when the route is jumped 缓存策略
, and the current routing component will not be refreshed. That is mounted
, the beforeDestory
waiting hook function will not be triggered. If you want to force refresh, you can assign a unique key to it on the root route. Adopt $route.fullpath
as its only key. In this way, Vue thinks that each internal route is a different route, and will force the component to be refreshed when jumping.
2. Problem solving:
3. Conclusion
In fact, there are many ways, such as passing v-if
, $nexttick
destroying routes before and after, and so on. But personally feel that the above method is the most elegant.