vue-router-tiny
A router for Vue.js
重写vue的router,使用Director作为底层框架。
去除vue-router原生bug:
- HTML5模式下,访问两次同样的地址,记录两次访问
- 配置/example/:id ,/example/1 跳转到/example/2 时不会重新渲染。
支持函数处理式的url跳转
- 支持url跳转进行函数处理
- 对url跳转添加了before,on,leave事件
原生vue实例
- 传递Vue实例参数,可以配合vuex使用。
- url事件中,this.vue可访问root vue。
Install
npm install
npm install vue-router-tiny
Download
git clone https://github.com/vvpvvp/vue-router
option
- history: 是否为html5模式
- rootUrl: 为所有的url都添加root,全局添加前缀url
- defaultUrl: 默认的url,当访问的地址没有route配置时,自动跳转。
- before: 所有的url跳转之前执行,返回false则停止跳转。
Use
main.html
demo
js/router.js
;;;; var routes = '/': component: main subRoutes: '/create1/:id': name: 'create1' component: create '/create2/:id': name: 'create2' { console; // return false;//会让页面无法跳转/welcome } { console; } { console; } component: create subRoutes: { console; console; } '/welcome': { ; } { console; } "/alert2": { ; } { ; } ; let VueParam = el: '#body'; Vue;var router = history:true rootUrl:"/root" defaultUrl:"/root"; router;routerstartVueParam; ;
注意:当配置了rootUrl时,无需将rootUrl添加至v-link中,包括调用go方法也无需添加。
components/menu.vue
welcome create1{{a}} create1{{b}} create2 alert
components/create.vue
welcome