You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Major rewrite. Directly extends from v-component. Add options and navigate.
Add Vue.navigate(path) method to manually trigger a page change. The 'routes' hash now takes an 'options' object containing the debug and broadcast booleans, as well as 3 new props: click, base and hashbang. Extends the latest version of v-component.
Copy file name to clipboardExpand all lines: README.md
+16-10Lines changed: 16 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@ vue-route
2
2
=======
3
3
4
4
Routing directive for Vue.js **(v0.11)**, inspired by ng-view.
5
-
`v-transition` are supported, as well as keep-alive.
5
+
Based on `v-component` thus benefits from `v-transition`, `keep-alive`, `wait-for`, `transition-mode`.
6
6
7
7
Allows you to declare your routes on the $root Vue object:
8
8
@@ -19,7 +19,9 @@ var root = new Vue({
19
19
componentId: 'fg-work',
20
20
afterUpdate: 'updateHeader'
21
21
},
22
-
broadcast: false
22
+
options: {
23
+
hashbang: true
24
+
}
23
25
},
24
26
})
25
27
@@ -33,7 +35,9 @@ with minimal markup:
33
35
</body>
34
36
35
37
```
36
-
It's heavily based on the `v-component` directive by @yyx990803 (on the [vuejs repo](https://github.com/yyx990803/vue/blob/0.11.0-rc3/src/directives/component.js)) so big up to him!
38
+
39
+
`vue-route` extends the `v-component` directive by @yyx990803 (on the [vuejs repo](https://github.com/yyx990803/vue/tree/master/src/directives/component.js)). Buy him a coffee if you can.
40
+
37
41
## Get started
38
42
39
43
**1.** Install with npm/component(1): `npm i vue-route --save` or `component install ayamflow/vue-route`.
@@ -61,17 +65,19 @@ Vue.use(route); // BOOM
61
65
**afterUpdate*: a callback (mehod or name of method on the vm) to call after effectively having changed to this route
62
66
**isDefault*: boolean indicating wether this page should be the default, in case of non-existing URL. Think of it as the `otherwise` from Angular, so basically a 404 or the home page.
63
67
68
+
Vue is augmented with an additional method, `Vue.navigate(path, [trigger])`. [trigger] is a boolean (defaults to true) that will `pushState` if true, `replaceState` otherwise.
69
+
64
70
* The router will emit events on your $root VM: `routing:started`, `routing:beforeUpdate`, `routing:afterUpdate`.
65
-
* You can pass a `broadcast` boolean. If set to true, the events will be emitted using the $root `$broadcast` method, so all child VMs will receive the event until a handler `return false;`. If false, it uses `$emit`. Defaults to `false`.
66
-
* You can pass a `debug` boolean to activate logging from the directive.
67
-
*`keep-alive` works the same way than with `v-component`.
71
+
* You can pass a `options` hash to pass configuration to the router:
72
+
*`hashbang` boolean (defaults to false) to use '#!' urls
73
+
*`click` boolean (defaults to true) to automatically bind all click to the router. Not that if `false`, you will need to explicitly call `Vue.navigate` method)
74
+
*`base` string (defaults to '/') to specify the base path
75
+
*`broadcast` boolean (defaults to false) if true the events will be emitted using the $root `$broadcast` method, so all child VMs will receive the event until a handler `return false;`. If false, it uses `$emit`.
76
+
*`debug` boolean (defaults to false) to activate logging from the directive.
68
77
69
78
## Location context
70
79
When the router emits an event, 2 parameters are passed: `location` and `oldLocation`. Like in Angular, it is an object containing some useful properties:
71
80
* regexp: the route regexp, such as `/items/:itemId`
72
81
* path: the current path, such as `/items/razor/`
73
82
* params: a hash of the params from the route, here `{item: 'razor'}`
74
-
* componentId: the componentId associated to the current route
75
-
76
-
## Todo
77
-
* transition timing (out then in, in then out, ...)
83
+
* componentId: the componentId associated to the current route
0 commit comments