1. cmtter-vue-router

cmtter-vue-router

介绍 ([email protected])

优化:问题描述如下

  初始创建的Router配置如下(注意404配置在二级目录中)

  import Router from 'vue-router'
  const router = new Router({
     routes: [
	    {
		  path: '/',
		  name: 'main',
		  component: ?,
		  children: [
			{
			  path: '*',
			  name: '404',
			  component: '?'
			}
		  ]
		}
	 ]
  })

 问题描述:

 我希望在404页面增加一些逻辑:根据菜单数据,按需router.addRoute添加路由配置,此时无法正常跳转,始终在404页面,

 解决方式(在 create-route-map.js 增加以下代码)

  /**
   *  [ '/*', '/a/*','/','/404' => [ '/404', '/', '/a/*', '/*' ]
   * @author xiufu.wang
   */
  const _pathList = pathList.splice(0).sort(function (a, b) {
    if (a.indexOf('*') > -1 && b.indexOf('*') < 0) {
      return 1
    }
    if (a.indexOf('*') < 0 && b.indexOf('*') > -1) {
      return -1
    }
    return b.length - a.length
  })

   for (var i = 0; i < _pathList.length; i++) {
     pathList.push(_pathList[i])
   }


Dependencies