路由導航守衛中document.title = to.meta.title的作用


路由導航守衛如下:

router.beforeEach(async (to, from, next) => {
  document.title = to.meta.title; // 路由發生變化時候修改頁面中的title
  const hasToken = store.getters.token;
  if (hasToken) {
    next();
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next();
    } else {
      next(`/login`);
    }
  }
});

1、當沒有document.title = to.meta.title,頁面發生跳轉時,效果如下:

即不管怎么切換,title標簽中的值總是為app-vue

2、當有document.title = to.meta.title,頁面發生跳轉時,效果如下:

即title標簽內包含當前頁面的meta.title的值

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM