一、场景:自己写的路由导航,每次刷新页面时,导航组件都会跳到默认选项。
刷新以后,页面路由和左侧路由对不上号。
二、解决办法:利用vue-router 的START_LOCATION 来初始化导航;
文档链接地址 https://router.vuejs.org/zh/api/#router-start-location
created(){
this.defaultRouter = this.$router.history._startLocation;
console.log(
`this.$router.history._startLocation`,
this.$router.history._startLocation
) // ==> 打印出来的是路由地址字符串 "/about"
},