File tree Expand file tree Collapse file tree 2 files changed +40
-8
lines changed Expand file tree Collapse file tree 2 files changed +40
-8
lines changed Original file line number Diff line number Diff line change @@ -44,3 +44,39 @@ export const routes = {
4444</template>
4545```
4646
47+ ### Attaching extra data to a route
48+
49+ ``` diff
50+ // routes.js
51+ import HomePage from './components/HomePage'
52+ import LoginPage from './components/LoginPage'
53+
54+ export const routes = {
55+ '/home': {
56+ component: HomePage,
57+ + // we are using `meta` as a good practice, but you are free to use something else
58+ + meta: { needsAuth: true }
59+ },
60+ '/login': {
61+ component: LoginPage,
62+ + meta: { needsAuth: false }
63+ },
64+ }
65+ ```
66+
67+ ``` xml
68+ <!-- anywhere in your templates -->
69+ <Label :text=" $navigator.route.meta.needsAuth" />
70+ ```
71+ ``` js
72+ // or in any vue component
73+ export default {
74+ methods: {
75+ doStuff () {
76+ if (this .$navigator .route .meta .needsAuth ) {
77+ // do stuff
78+ }
79+ }
80+ }
81+ }
82+ ```
Original file line number Diff line number Diff line change @@ -22,17 +22,13 @@ export default function install(Vue, {routes}) {
2222 } ,
2323 computed : {
2424 route ( ) {
25- return this . _resolveRoute ( this . path )
25+ return routes [ this . path ]
2626 } ,
2727 } ,
2828 methods : {
29- _resolveRoute ( path ) {
30- return routes [ path ]
31- } ,
32- _resolveComponent ( path ) {
33- const route = this . _resolveRoute ( path )
34- if ( route ) {
35- return route . component
29+ _resolveComponent ( ) {
30+ if ( this . route ) {
31+ return this . route . component
3632 }
3733 return false
3834 } ,
You can’t perform that action at this time.
0 commit comments