this.$router.history._startLocation

一、场景:自己写的路由导航,每次刷新页面时,导航组件都会跳到默认选项。

刷新以后,页面路由和左侧路由对不上号。
在这里插入图片描述

二、解决办法:利用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" 
  },

版权声明:本文为qq_45301392原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。