Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that vue-router 's beforeRouteUpdate is not triggered?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "how to solve the problem without triggering the beforeRouteUpdate of vue-router". The small editor shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how to solve the problem without triggering the beforeRouteUpdate of vue-router" can help you solve the problem.

vue-router beforeRouteUpdate does not trigger

The official explanation for beforeRouteUpdate is as follows:

beforeRouteUpdate (to, from, next) { //Called when the current route changes but the component is multiplexed //For example, for a path/foo/:id with dynamic parameters, jump between/foo/1 and/foo/2 //Component instances are reused because the same Foo component is rendered. And that hook will be called in this case. //can access component instance `this` },

The reason why it cannot be triggered can be seen in the second and third lines of the comment, only the path of dynamic parameters (/foo/1 and/foo/2) will be called.

I try to handle router dynamics

vue.$ router.push({ path: path , query: { t: (new Date()) }});

In this scenario, beforeRouteUpdate was triggered successfully.

You can consider modifying your router-link writing and adding a parameter. The code example is as follows:

home

Of course, the main thing is that this method is the navigation guard within the component, switching routing components, according to your current code function, if you want to trigger,

In addition to router-link with parameters, you also need to modify router-view

Alternatively, the following solutions could be adopted:

watch: { $route(to, from) { console.log(to); console.log(from); } }

Also try vue-router route jump created not executed, page does not refresh solution

beforeRouteEnter and beforeRouteUpdate pits

beforeRouteEnter is a newly entered route, such as entering the/login login interface, which will trigger the beforeRouteEnter hook;

beforeRouteUpdate is triggered when the route is updated. Entering the login interface from the homepage will not trigger this hook function. A child route jump under a parent route will trigger this hook function.

About "vue-router beforeRouteUpdate does not trigger the problem how to solve" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report