Next usage problems in vue: router.beforeEach, next ({.to})

download a demo for dynamic permission routing with vue and vuex from the Internet

clipboard.png

When the

code comes to the step of next, I can"t understand it. I found a lot of it on the Internet, and I didn"t find the explanation of next ({.to})
. It"s brain-burning, I can"t understand

.
Mar.22,2021

next ('/') or next ({path:'/'}): jump to a different address. The current navigation is interrupted, and then a new navigation is carried out. You can pass objects anywhere to next, and allow you to set options such as replace: true, name: 'home', and any options used in router-link 's to prop or router.push.

there are original words on the official website: Navigation Guard


ES2015's syntax extension operator (.)
equals to writing all the variables of to , in fact, if the interior does not change, it is the same as whether or not to write curly braces directly. If it changes internally, it will be different

clipboard.png

clipboard.png


what does it mean to set replace:true in next? can you explain


this is the hook function before vue-router jump to determine whether you have permission or not? if you have permission, you can load the route returned by the backend, and then jump to it. When you call this function, isn't there a to,from,next coming in? to is the page you want to go to


, so what's the difference between this and direct next ()?

Menu