鍍金池/ 問答/HTML/ vue-router動(dòng)態(tài)路由匹配了正常的路由怎么辦?

vue-router動(dòng)態(tài)路由匹配了正常的路由怎么辦?

問題描述

當(dāng)定義一個(gè)動(dòng)態(tài)路由如/user/:id時(shí),在定義一個(gè)正常路由/user/edit,但是當(dāng)訪問后者的時(shí)候,跳轉(zhuǎn)到了前面的路由,不知道該怎么匹配

相關(guān)代碼

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      component: () => import('./views/index/Index.vue'),
      children: [
        {
          path: '/',
          redirect: {
            name: 'index'
          }
        },
        {
          path: '/index',
          name: 'index',
          component: () => import('./views/pages/Home.vue')
        },
        {
          path: 'user/:id',
          name: 'user_post',
          component: ()=>import('./views/pages/Article.vue')
        }
      ]
    },
    {
      path: '/user',
      component: () => import('./views/users/User.vue'),
      children: [
        {
          path: '',
          redirect: {
            name: 'profile'
          }
        },
        {
          path: 'profile',
          name: 'profile',
          component: () => import('./components/user/Profile.vue')
        },
        {
          path: 'editor',
          name: 'editor',
          component: () => import('./components/user/Editor.vue')
        }
      ]
    }
  ]
})

我期望的是首頁中通過用戶id訪問用戶的首頁,然后/user/profile、/user/editor等是登錄之后用戶首頁信息、編輯文章等的路由,但是現(xiàn)在訪問/user/editor直接跳轉(zhuǎn)到/user/:id即user_post的路由了,不知道有什么好的解決辦法嗎?

回答
編輯回答
不討喜

之前也遇到過,但是沒想到辦法,只能將/user/:id轉(zhuǎn)換成query訪問

2017年9月5日 22:43