be.title.js 718 B

1234567891011121314151617181920
  1. import { setTitle } from "@vci/helper/src/document";
  2. import { isEmpty } from "@vci/helper/src/other";
  3. /**
  4. * 路由导航前处理 标题设置
  5. * @param router 路由实例
  6. * @param name 项目名称
  7. */
  8. export const beforeEachForTitle = (router, name) => {
  9. if(!name) {
  10. console.warn("请在主程序路由配置文件中引入package.json\n将其中的name-zh赋给`name`!");
  11. console.warn("如果package.json中没有name-zhe这个属性,请自动添加: \n他的作用是用来显示页面的标题!");
  12. }
  13. router.beforeEach((to, from, next) => {
  14. if(name && to.meta && !isEmpty(to.meta["title"])) setTitle(`${name} - ${to.meta["title"]}`);
  15. else setTitle(name);
  16. next();
  17. });
  18. };