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

相关推荐
lightgis18 分钟前
16openlayers加载COG(云优化Geotiff)
前端·javascript·html·html5
小飞大王66623 分钟前
TypeScript核心类型系统完全指南
前端·javascript·typescript
你的人类朋友2 小时前
✍️记录自己的git分支管理实践
前端·git·后端
合作小小程序员小小店3 小时前
web网页开发,在线考勤管理系统,基于Idea,html,css,vue,java,springboot,mysql
java·前端·vue.js·后端·intellij-idea·springboot
防火墙在线3 小时前
前后端通信加解密(Web Crypto API )
前端·vue.js·网络协议·node.js·express
Jacky-0083 小时前
Node + vite + React 创建项目
前端·react.js·前端框架
CoderYanger4 小时前
前端基础——CSS练习项目:百度热榜实现
开发语言·前端·css·百度·html·1024程序员节
i_am_a_div_日积月累_4 小时前
10个css更新
前端·css
她是太阳,好耀眼i4 小时前
Nvm 实现vue版本切换
javascript·vue.js·ecmascript
蒲公英10014 小时前
在wps软件的word中使用js宏命令设置表格背景色
javascript·word·wps