universe:collection-links

v0.5.1Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Universe Collection Links

This package can help you with binding routes with collection and its document. It works for FlowRouter ( but It can works with Iron Router too. - Not tested for Iron Router yet)

Creating routes

1Books = new UniCollection('books');
2
3Books.setCollectionRoute('/books', {
4    // default name for collection route is 'listing'
5    name: 'listing',
6    action () {
7        // ...
8    }
9});
10
11Books.setCollectionRoute('/book/:_id', {
12    // default name for document route is 'fullview'
13    name: 'fullview',
14    action (params) {
15        // ...
16    }
17});
18
19Books.setCollectionRoute('/short_page/:_id', {
20    // custom name of route
21    name: 'shortview',
22    action (params) {
23        // ...
24    }
25});

Getting path

.getLink('routeName', params, queryParams) returns link for route

1var doc = Books.findOne();
2//default route for document is fullview (parameter(s) of route must be the same as key(s) of document)
3doc.getLink(); //output: '/book/ac9b43533dd'
4
5doc.getLink('shortview'); //output: '/short_page/ac9b43533dd'
6
7Books.getLink(); //output: '/books'
8
9Books.getLink('listing'); //output: '/books'
10
11FlowRouter.path('booksListing'); //output: '/books'
12// You can use IronRouter instead FlowRouter as well but for now it is not tested.
13
14//From collection to get link for route with params) you must pass them.
15Books.getLink('fullview', {_id: 'ac9b43533dd'}); //output: '/book/ac9b43533dd'

Use .goToLink() instead .getLink() to change current route.