New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Existing Iron-Router Route? #104

Open
voidale opened this Issue Dec 8, 2014 · 8 comments

Comments

Projects
None yet
7 participants
@voidale

voidale commented Dec 8, 2014

I can't figure out if it's possible to use existing route, If I use existing one it will throw an error saying it's already exists, The thing is I want to include the table inside existing route inside that theme in some part of it. The examples don't really show you how to do it... Thank you!

Also another small question, I want a table. I also want to include checkboxes + action column where will be 2 buttons edit/remove. I should try not to use the table and try to create it with template helpers myself? If thats possible

@radzserg

This comment has been minimized.

radzserg commented Jan 15, 2015

+1 for first question. If you have existed route with some logic in data, waitOn functions there's no obvious way how to integrate it with pagination.
Moreover meteor pages generate routes but IMO in most cases it's much more convenient if existed routes can use pagination.

@evenfrost

This comment has been minimized.

evenfrost commented Feb 18, 2015

Same question here.

@alethes

This comment has been minimized.

Owner

alethes commented Mar 7, 2015

Using your own route is possible, although you'll need to set up your own navigation controls. There's currently no way to let Pages know how to navigate between routed pages unless it sets the routes by itself. I plan to implement it soon and make the API intuitive for both automated route creation and integration with existing routes.

Currently, you could do the following:

  • Place your Meteor.Pagination invocation in the common code.
  • Since you don't need pages to set up the routes, don't use any of the router-related settings.
  • Set template to the name of your route's template.
  • Place {{> pages}} (but not {{> pagesNav}}) somewhere in your route's template.
  • Include all pages-related logic in your route. Call the set() method from iron-router helpers whenever you want to change some settings based on your route's parameters, eg. Pages.set({perPage: this.params.perPage}).
  • To change the current page based on the route's parameter, use the sess() method, eg. Pages.sess("currentPage", this.params.page).
  • Set up your own navigation controls pointing to subsequent pages. Pages won't let you navigate to non-existent pages, but you can check the number of the last page with Pages.sess("totalPages"). The easiest way to do this might look something like:
<a href=prevLink>Previous</a>
<a href=nextLink>Next</a>
function getRoute(d){
  if(!d)d = 0;
  pageNumber = Pages.sess("currentPage") + d;
  if(_.isNaN(pageNumber)) //just in case sess("currentPage") is not yet defined.
    pageNumber = 1;
  return "/my/route/" + pageNumber;
}
Template.myTemplate.helpers({
  prevLink: _.partial(getRoute, -1), //getRoute with d set to -1
  nextLink: _.partial(getRoute, 1) //getRoute with d set to 1
});
@AlexFrazer

This comment has been minimized.

AlexFrazer commented Mar 20, 2015

yep yep, would be nice if this was on the README.md

@funkybunky

This comment has been minimized.

funkybunky commented Apr 1, 2015

did anyone try this out, yet? does it work?

@KyleKing

This comment has been minimized.

KyleKing commented Apr 10, 2015

How do you override the Meteor-pages package routing?

For example, I get:

W20150410-12:37:16.191(-4)? (STDERR)
W20150410-12:37:16.191(-4)? (STDERR) /Users/kyleking/.meteor/packages/meteor-tool/.1.1.3.17mp0v2++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20150410-12:37:16.191(-4)? (STDERR)                        throw(ex);
W20150410-12:37:16.191(-4)? (STDERR)                              ^
W20150410-12:37:16.229(-4)? (STDERR) Error: A route for the path "/" already exists by the name of "items_home0".
W20150410-12:37:16.229(-4)? (STDERR)     at Iron.utils.assert (packages/iron:core/lib/iron_core.js:10:1)
W20150410-12:37:16.229(-4)? (STDERR)     at Function.Router.route (packages/iron:router/lib/router.js:137:1)
W20150410-12:37:16.229(-4)? (STDERR)     at Function.<anonymous> (packages/alethes:pages/lib/pages.coffee:439:14)
W20150410-12:37:16.229(-4)? (STDERR)     at Function.Router.map (packages/iron:router/lib/router.js:91:1)
W20150410-12:37:16.229(-4)? (STDERR)     at Pages.__Pages.Pages.setRouter (packages/alethes:pages/lib/pages.coffee:413:14)
W20150410-12:37:16.229(-4)? (STDERR)     at new Pages (packages/alethes:pages/lib/pages.coffee:114:6)
W20150410-12:37:16.230(-4)? (STDERR)     at both/meteorPagesPublications/testData.coffee:13:14
W20150410-12:37:16.230(-4)? (STDERR)     at both/meteorPagesPublications/testData.coffee:3:1
W20150410-12:37:16.230(-4)? (STDERR)     at /Users/kyleking/Documents/Developer/Meteor/TeamBIKES/TeamBIKES/.meteor/local/build/programs/server/boot.js:222:10
W20150410-12:37:16.230(-4)

Updated Solution:
(Should have spent more time reading the docs)
But for anyone who reads this, you can add:

// Configure the base route
homeRoute: '/my route/'
@alethes

This comment has been minimized.

Owner

alethes commented Apr 10, 2015

Just don't use the router option. There's no routing by default.

On 10 Apr 2015, at 18:38, Kyle King notifications@github.com wrote:

How do you override the Meteor-pages package routing?

For example, I get:

W20150410-12:37:16.191(-4)? (STDERR)
W20150410-12:37:16.191(-4)? (STDERR) /Users/kyleking/.meteor/packages/meteor-tool/.1.1.3.17mp0v2++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20150410-12:37:16.191(-4)? (STDERR) throw(ex);
W20150410-12:37:16.191(-4)? (STDERR) ^
W20150410-12:37:16.229(-4)? (STDERR) Error: A route for the path "/" already exists by the name of "items_home0".
W20150410-12:37:16.229(-4)? (STDERR) at Iron.utils.assert (packages/iron:core/lib/iron_core.js:10:1)
W20150410-12:37:16.229(-4)? (STDERR) at Function.Router.route (packages/iron:router/lib/router.js:137:1)
W20150410-12:37:16.229(-4)? (STDERR) at Function. (packages/alethes:pages/lib/pages.coffee:439:14)
W20150410-12:37:16.229(-4)? (STDERR) at Function.Router.map (packages/iron:router/lib/router.js:91:1)
W20150410-12:37:16.229(-4)? (STDERR) at Pages.__Pages.Pages.setRouter (packages/alethes:pages/lib/pages.coffee:413:14)
W20150410-12:37:16.229(-4)? (STDERR) at new Pages (packages/alethes:pages/lib/pages.coffee:114:6)
W20150410-12:37:16.230(-4)? (STDERR) at both/meteorPagesPublications/testData.coffee:13:14
W20150410-12:37:16.230(-4)? (STDERR) at both/meteorPagesPublications/testData.coffee:3:1
W20150410-12:37:16.230(-4)? (STDERR) at /Users/kyleking/Documents/Developer/Meteor/TeamBIKES/TeamBIKES/.meteor/local/build/programs/server/boot.js:222:10
W20150410-12:37:16.230(-4)

Reply to this email directly or view it on GitHub.

@KyleKing

This comment has been minimized.

KyleKing commented Apr 10, 2015

Thanks! I configured routing with your API with 3 lines, thanks for such a robust package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment