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

相关推荐
用户0165238444120 分钟前
Webpack5 入门与实战,前端开发必备技能无密
前端
小高00720 分钟前
🔥🔥🔥前端性能优化实战手册:从网络到运行时,一套可复制落地的清单
前端·javascript·面试
古夕23 分钟前
my-first-ai-web_问题记录01:Next.js的App Router架构下的布局(Layout)使用
前端·javascript·react.js
Solon阿杰26 分钟前
solon-flow基于bpmnJs的流程设计器
javascript·bpmn-js
Solon阿杰26 分钟前
前端(react/vue)实现全景图片(360°)查看器
javascript·vue.js
杨超越luckly29 分钟前
HTML应用指南:利用POST请求获取上海黄金交易所金价数据
前端·信息可视化·金融·html·黄金价格
郝学胜-神的一滴29 分钟前
Three.js 材质系统深度解析
javascript·3d·游戏引擎·webgl·材质
Jerry33 分钟前
Compose 中的基本布局
前端
Hilaku39 分钟前
深入WeakMap和WeakSet:管理数据和防止内存泄漏
前端·javascript·性能优化
Juchecar42 分钟前
常见的 HTML 标签及 CSS 选择器速查表
前端