vue2.0 路由自动化范例

//***路由自动化START***
//循环目录
let routers = require.context('@/views', true).keys();
//过滤含有.vue的文件
routers = routers.filter(item => item.indexOf(".vue") != -1);

let indexRouterArray=[];
let rtIndexRouterArrayPath={};
//循环目标文件
routers.forEach(item => {
	const paths = item.match(/[a-zA-Z]+/g) //paths中存储了一个目录,二级目录,文件名
	let pageI=item.replace(/\.\//g,"").replace(/\.vue/g,"");

	let routerData= {
		path: '/' + pageI,
		name:"A_"+pageI.replace(/\//g,"_"),
		component: () => import("@/views/"+pageI),
	}
	//如果目录下的文件名是index.vue 路由直接是目录名
	if(paths[paths.length-2]=="index"){
		routerData.path=routerData.path.replace(/\/index/g,"")
	}
	rtIndexRouterArrayPath[item]={
		path:routerData.path,
		name:routerData.name
	};
	indexRouterArray.push(routerData);
})

console.log("自动化路由路径", rtIndexRouterArrayPath)
//合并手动路径和自动路径
routesArray=routesArray.concat(indexRouterArray)
//***路由自动化END***

通过自动化路由,配置出所有相关page页面地址。

可以缓解多人协作模式下,对于单一路由文件的编辑冲突和统一化。

类别:

10回应

  1. sikis izle说道:

    I pay a quick visit each day a few websites and sites to read articles or reviews, however this webpage gives quality based writing. Gwenneth Elmer Holle

  2. sikis izle说道:

    Way cool! Some very valid points! I appreciate you writing this post and also the rest of the website is also really good. Mariann Simon Kentiggerma

  3. sikis izle说道:

    I believe you have mentioned some very interesting details, regards for the post. Catherin Nico Berry

  4. porno说道:

    You have observed very interesting details! ps nice internet site. Delly Vladimir Amalbena

  5. porn说道:

    Hello! This is my 1st comment here so I just wanted to give a quick shout out and tell you I really enjoy reading your posts. Beatriz Patric Glanville

  6. netflix说道:

    Wow, incredible blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your website is fantastic, let alone the content! Morna Delmore Pauwles

  7. movies说道:

    Hurrah! After all I got a blog from where I be capable of really take helpful data concerning my study and knowledge.| Antonia Cal Bent

  8. online说道:

    Excellent site. Lots of helpful information here. I am sending it to some buddies ans additionally sharing in delicious. And naturally, thank you to your sweat! Kelsy Ewan Wanfried

  9. online说道:

    Hmm is anyone else experiencing problems with the images on this blog loading? Hilliary Hersh Byrd

  10. watch online说道:

    This is one awesome article post. Really looking forward to read more. Hyacintha Kalil Ronny Evania Cornelius Clift

movies进行回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Copyright @ 2019 ARVIN 版权所有 沪ICP备19014233号-1