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

相关推荐
weixin_4316004427 分钟前
NestJS 入门(3):Guard 如何挡住未登录请求?
前端·后端·学习·nest.js
avi911133 分钟前
[AI教做人]AI平台做2项目;一个3D模型展示,另一个框架多人
javascript·人工智能·ai·3d模型·3d引擎·顶点和法线
kyriewen44 分钟前
我用Claude Code两天干完了团队两周的排期——周报发出去那一刻我就后悔了
前端·javascript·ai编程
IT_陈寒1 小时前
JavaScript类型转换把我坑惨了,这破玩意真该早点搞明白
前端·人工智能·后端
用户938515635071 小时前
Type vs Interface:读完这篇就没有面试官能难倒你了
前端·面试·typescript
用户938515635072 小时前
手写一个 LLM Harness 框架:用工程化手段把大模型幻觉踩在脚下
javascript·人工智能·后端
油丶酸萝卜别吃2 小时前
jquery-ajax.js 说明文档
前端·javascript·jquery
windliang2 小时前
Claude Code 源码分析(九):子 Agent 如何分叉、继续与回到父会话
前端·javascript·面试
柒和远方3 小时前
V063: TS 面试必考:interface 与 type 的四大差异,与 LLM Harness 的自动化择优
前端·javascript
半个落月3 小时前
React useRef 详解:DOM 引用、持久化值与 Worker 实例
前端·react.js