vue router.js 传值,根据不同type显示不同内容

vue router.js 传值,根据不同type显示不同内容


el-bread 封装

router.js

javascript 复制代码
import Vue from 'vue'
import Router from 'vue-router'

// 路由前缀
const { prefixBasePath } = require('../../config/basePath')

// 解决重复点击一个路由报错问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)

const router = new Router({
  base: prefixBasePath, // 路由前缀
  mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      name: 'login',
      path: '/login',
      component: resolve => (require(['@/components/login'], resolve)),
      meta: {
        title: '登录',
        keepAlive: true
      },
    },
    {
      name: 'home',
      path: '/home',
      component: resolve => (require(['@/components/header/haveMenuIndex'], resolve)),
      meta: {
        title: '首页',
        keepAlive: true
      },
      children: [
        {
          name: 'mine',
          path: '/mine',
          component: resolve => (require(['@/components/mine'], resolve)),
          meta: {
            title: '个人中心',
            keepAlive: true,
          },
          children: [
            {
              name: 'news',
              path: 'news/:type', // 完整路由:/about/news/1
              component: resolve => require(['@/components/mine/financialAssist'], resolve),
              meta: {
                title: null,
                keepAlive: true,
              },
              beforeEnter: (to, from, next) => {
                // 根据type参数设置meta字段
                to.meta.title = to.params.type == 1 ? '已读信息' : to.params.type == 2 ? '未读信息' : '';
                next();
              }
            },
          ]
        },
        {
          name: 'about',
          path: '/about',
          component: resolve => (require(['@/components/about'], resolve)),
          meta: {
            title: '关于',
            keepAlive: true,
          }
        },
      ]
    },
  ]
})
// 路由守卫
router.beforeEach((to, from, next) => {
  next()
})
export default router

相关推荐
ModyQyW36 分钟前
vite-plugin-uni-manifest 更新了什么
前端·typescript·uni-app
Asize2 小时前
AI 协作开发新范式:我用 SDD 做了个排版 npm 包
前端·人工智能
kyriewen3 小时前
我把今年流传的前端 AI 面试题整理了一遍——4 类场景题+回答框架(附速查表)
前端·面试·程序员
计算机魔术师4 小时前
国产多模态模型正面硬刚Opus旗舰:差距从30%缩到3%
前端
风骏时光牛马4 小时前
程序员进阶:深度思考,解锁职场成长的底层逻辑
前端
IT_陈寒4 小时前
用了Proxy才发现以前的JavaScript白写了
前端·人工智能·后端
爱丶不疚4 小时前
Eval: Agent 说的 Eval 是什么?从单测、TDD 到 Sentry 聊起
前端·ai编程·vibecoding
求道於盲5 小时前
python中的类型标注
前端
计算机魔术师5 小时前
从硅谷测试到全球铺开,ChatGPT广告的10亿美元秘密
前端
专业抄代码选手6 小时前
08|Fiber 上的 `useState`:状态终于属于具体组件
前端·javascript·react.js