一.route 對象
1).$route.path //當前網頁的路由地址 index/test
2).$route.params //一個 key/value 對象,包含了動態片段和全匹配片段,如果沒有路由參數,就是一個空對象。
/index/bar:1 打印參數 { "id": ":1" }
3).$route.query // index?user=3 打印參數 { "user": "3" }
4).$route.fullpath // 完成解析後的 URL,包含查詢參數和 hash 的完整路徑。
5).$route.matched
- 類型:
Array<RouteRecord>
一個數組,包含當前路由的所有嵌套路徑片段的路由記錄 。路由記錄就是 routes
配置數組中的對象副本 (還有在 children
數組)。
遍歷如下:
let matched = this.$route.matched.filter(item => item.name)
this.listLeve = matched
this.listLeve.forEach(
i => alert(i.name)
)
6).$route.hash //當前路由的 hash 值 (帶 #
) ,如果沒有 hash 值,則爲空字符串。
//路由表
export default new Router({
routes: [
{
path: '/index',
name: '主頁',
component: HelloWorld,
children: [
{
path: 'test',
name: '測試頁面',
component: Test
}
]
}
]
})