update
uni-simple-router 3.0 版本已发布,欢迎你的使用!

# 基本路由配置







 


















const router = new Router({
  routes:[
    {
        //注意:path必须跟pages.json中的地址对应,最前面别忘了加'/'哦
	    path: '/pages/home/index',
		name: 'index',//在路由跳转时可直接使用name来跳转,后面会讲到
		aliasPath:'/',  //对于h5端你必须在首页加上aliasPath并设置为/
        //可以自定义路由元信息
        myDiy:{
            isTab:true
        },
        meta: {
	        title: '首页',
	    },
    },
    {
	    path: '/pages/home/list',
        name: 'list',
        meta: {
	        title: '列表',
	    },
	},
  ]
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

你可以在路由守卫中读取。

router.beforeEach((to, from, next) => {
	if(to.myDiy.isTab){
        //..执行相关逻辑
    }
	next()
})

1
2
3
4
5
6
7

你也可以在对应的组件内查看相关路由元信息

<!-- pages/home/index.vue -->
<template>
	<view>
		<h1>home</h1>
	</view>
</template>

<script>
	export default {
		onLoad() {
			console.log(this.$Route.myDiy); //{ isTab:true }
		}
	}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14