Skip to content

Commit 2521e2c

Browse files
committed
Breaking changes in vue-router
1 parent c030e76 commit 2521e2c

File tree

11 files changed

+78
-858
lines changed

11 files changed

+78
-858
lines changed

.meteor/packages

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ apollo
2323
ccorcos:subs-cache
2424
meteorhacks:fast-render
2525

26-
akryum:vue-app
26+
akryum:vue
27+
akryum:vue-component
28+
akryum:vue-router
29+
akryum:vuex
2730
akryum:vue-apollo
31+
akryum:vue-i18n
2832
akryum:vue-i18n-ui
2933
akryum:vue-less
3034
akryum:vue-sass

.meteor/versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ akryum:vue-i18n@0.0.3
1111
akryum:vue-i18n-ui@0.0.4
1212
akryum:vue-jade@0.0.1
1313
akryum:vue-less@0.0.3
14-
akryum:vue-router@0.1.2
14+
akryum:vue-router@0.2.0
1515
akryum:vue-sass@0.0.1
1616
akryum:vue-stylus@0.0.1
1717
akryum:vuex@0.3.0

client/main.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import {Router} from 'meteor/akryum:vue-router';
66
// Api
77
import '/imports/api/methods';
88

9-
// Routes
10-
//import './routes';
11-
129
// Subscriptions cache
1310
const subsCache = new SubsCache({
1411
expireAfter: 15,
@@ -21,20 +18,23 @@ Vue.config.meteor.subscribe = function(...args) {
2118
return subsCache.subscribeFor.apply(subsCache, args);
2219
};
2320

21+
// Router
22+
const router = new Router({
23+
history: true,
24+
saveScrollPosition: true
25+
});
26+
2427
// App layout
2528
import AppLayout from '/imports/ui/AppLayout.vue';
2629

2730
// Not found
2831
import NotFound from '/imports/ui/NotFound.vue';
29-
Router.on('*', {
32+
router.on('*', {
3033
component: NotFound
3134
});
3235

3336
// App start
3437
Meteor.startup(function() {
3538
// Start the router and create root vue instance
36-
Router.start({
37-
history: true,
38-
saveScrollPosition: true
39-
}, AppLayout, '#app');
39+
router.start(AppLayout, '#app');
4040
});

packages/vue-router/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
## 0.2.0 - 2016/07/06
4+
5+
- (BREAKING CHANGE) You now have to create the router instance from the `Router` class in your client.
6+
- (BREAKING CHANGE) The `Router` class now extends the native vue-router class directly. `Router.lib` removed.

packages/vue-router/README.md

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the [example here](https://github.com/Akryum/meteor-vue-example-routing).
1414

1515
### Route definition
1616

17-
In your client, add some routes (for more info about route definition, check the [vue-router documentation](http://router.vuejs.org/en/nested.html)):
17+
In your client, add some routes with the `Router.configure()` method (for more info about route definition, check the [vue-router documentation](http://router.vuejs.org/en/nested.html)):
1818

1919
```javascript
2020
/* /client/routes.js */
@@ -27,23 +27,27 @@ import Home from '/imports/ui/Home.vue';
2727
import Forum from '/imports/ui/Forum.vue';
2828
import Apollo from '/imports/ui/Apollo.vue';
2929

30-
// Simple routes
31-
Router.map({
32-
'/': {
33-
name: 'home',
34-
component: Home
35-
},
36-
'/forum': {
37-
name: 'forum',
38-
component: Forum
39-
},
40-
'/apollo': {
41-
name: 'apollo',
42-
component: Apollo
43-
}
30+
Router.configure(router => {
31+
// Simple routes
32+
router.map({
33+
'/': {
34+
name: 'home',
35+
component: Home
36+
},
37+
'/forum': {
38+
name: 'forum',
39+
component: Forum
40+
},
41+
'/apollo': {
42+
name: 'apollo',
43+
component: Apollo
44+
}
45+
});
4446
});
4547
```
4648

49+
The callbacks you pass to the `Router.configure()` calls will be called before the router is started, regardless of the file load order.
50+
4751
#### Simple syntax
4852

4953
You can use an alternative special syntax in `.routes.js` files:
@@ -132,12 +136,18 @@ export default {
132136
To add a 'not found' page, add a `*` route in your client code:
133137
134138
```javascript
135-
/* /client/client.js */
139+
/* /client/routes.js */
140+
141+
// Import the router
142+
import {Router} from 'meteor/akryum:vue-router';
136143
137144
// Not found
138145
import NotFound from '/imports/ui/NotFound.vue';
139-
Router.on('*', {
140-
component: NotFound
146+
147+
Router.configure(router => {
148+
router.on('*', {
149+
component: NotFound
150+
});
141151
});
142152
```
143153
@@ -152,38 +162,34 @@ Then import the routes and start the router in your client:
152162
import {Meteor} from 'meteor/meteor';
153163
import {Router} from 'meteor/akryum:vue-router';
154164
165+
// Create the router instance
166+
const router = new Router({
167+
history: true,
168+
saveScrollPosition: true
169+
});
170+
155171
// App layout
156172
import AppLayout from '/imports/ui/AppLayout.vue';
157173
158174
// App start
159175
Meteor.startup(() => {
160-
// Start the router and create root vue instance
161-
Router.start({
162-
history: true,
163-
saveScrollPosition: true
164-
}, AppLayout, 'app');
176+
// Start the router
177+
router.start(AppLayout, 'app');
165178
});
166179
```
167180
168181
**If you put your routes files in the `/imports` folder, you need to import them manually.**
169182
170-
The most important method is `Router.start(options, App, el, callback)` that takes these parameters:
183+
When you create the router instance, you can pass `options` that allow you to customize the router behavior ([more info](http://router.vuejs.org/en/options.html)).
184+
185+
To start the router, use the `router.start(App, el, callback)` method inside a `Meteor.startup()` call. It takes these parameters:
171186
172-
- `options` allow you to customize the router behavior ([more info](http://router.vuejs.org/en/options.html)).
173187
- `App` is a vue component definition that will be used as the main layout and root instance. **Note that the router cannot be started with Vue instances.**
174188
- `el` determines which HTML element the root instance will be attached on ([more info](https://vuejs.org/api/#el)). Can be a CSS selector string or an actual element.
175189
- `callback` is an optional function which will be called when the router app's initial render is complete.
176190
177191
For more info about router start, check the [vue-router documentation](http://router.vuejs.org/en/api/start.html).
178192
179-
### Access all the `vue-router` methods
180-
181-
Use the `lib` property:
182-
183-
```javascript
184-
Router.lib.on('/home', {...});
185-
```
186-
187193
### Fast-render
188194
189195
You can use the [meteorhacks:fast-render](https://github.com/kadirahq/fast-render) package to inject the subscriptions data in the html. This greatly speeds up the initial render of your app if it depends on subscriptions.

packages/vue-router/client/client.js

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,27 @@ import VueRouter from 'vue-router';
33

44
Vue.use(VueRouter);
55

6-
class RouterClass {
7-
constructor() {
8-
this._defs = [];
9-
}
10-
11-
map(def) {
12-
this._defs.push(def);
13-
}
6+
export class Router extends VueRouter {
7+
constructor(options) {
8+
super(options);
149

15-
on(path, options) {
16-
this._defs.push({
17-
[path]: options
18-
});
19-
}
20-
21-
start(options, App, el, callback) {
22-
this.lib = new VueRouter(options);
23-
for(let def of this._defs) {
24-
this.lib.map(def);
25-
}
26-
this.lib.start(App, el, callback);
10+
Router.instance = this;
11+
Router._init(this);
2712
}
2813
}
2914

15+
const _initCbs = [];
3016

31-
export const Router = new RouterClass();
17+
Router._init = function(instance) {
18+
_initCbs.forEach(cb => {
19+
cb(instance);
20+
});
21+
};
3222

33-
/*export function getData(id) {
34-
let fastData = window.__fast_data__;
35-
if(fastData) {
36-
return fastData[id];
23+
Router.configure = function(cb) {
24+
if(Router.instance) {
25+
cb(Router.instance);
26+
} else {
27+
_initCbs.push(cb);
3728
}
38-
}*/
29+
}

packages/vue-router/package.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'akryum:vue-router',
3-
version: '0.1.2',
3+
version: '0.2.0',
44
summary: 'Easy vue routing for Meteor',
55
git: 'https://github.com/Akryum/meteor-vue-component',
66
documentation: 'README.md'
@@ -24,8 +24,6 @@ Package.onUse(function(api) {
2424
api.use('ecmascript');
2525
api.use('akryum:npm-check@0.0.2');
2626
api.use('akryum:vue@1.0.2');
27-
//api.use('webapp', 'server');
28-
//api.mainModule('server/server.js', 'server');
2927
api.mainModule('client/client.js', 'client');
3028
api.export('Router', 'client');
3129
});

packages/vue-router/plugin/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class VueRouterCompiler extends CachingCompiler {
3232
code = code.replace(componentReg, 'component: require($1).default');
3333
code = 'let r = (()=>{' + code + `})();
3434
import {Router} from 'meteor/akryum:vue-router';
35-
Router.map(r);`;
35+
Router.configure(router => { router.map(r); })`;
3636
let map = '';
3737

3838
let babelOptions = Babel.getDefaultOptions();

packages/vue-router/server/dsl.js

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)