1

I'd like to handle the case properly where a URL might be just slightly off (e.g. mistyped, wrong case) in my Meteor app and I'm using iron:router for routing.

How can I define my regular routes and then define some kind of "catch all" route or "no routes found" callback? Does iron:router provide such capabilities or are there easy workarounds or community packages?

I can sort of work around this by doing something like

Router.route('/:slug', ...)

last. But as soon as routes are defined not just from within the main app but also from packages I get in trouble because there's no way to say "and run this particular route last".

Thanks everybody!

seeekr
  • 101
  • 1
  • 9

2 Answers2

1

Would something like this work?

this.route('notFound', { path: '*' });

http://www.manuel-schoebel.com/blog/iron-router-tutorial

Orbit
  • 2,985
  • 9
  • 49
  • 106
  • Unfortunately not! It's just a slightly different syntax with the same meaning as `Router.route('/(.*)', {name: 'notFound'})` and on the link you posted it specifically says this: `//// Define a global not found route as the very last route in your router` -- and I don't have a place that is guaranteed to be called last. – seeekr May 31 '15 at 09:32
0

Yeah, first of all, what you are using is an old iron:router api, check its documentation for newest routes handling.

Router handles RegEx so you can create your LAST route that catches any string.

For syntax check my earlier answer for this: Meteor infinite redirect instead of render 404

Community
  • 1
  • 1
sdooo
  • 1,851
  • 13
  • 20
  • Updated API usage, thanks for catching that. (Whoops, sent too early.) I understand what you're saying, but the real question is "how do I define a route that is guaranteed to run last?" – seeekr May 30 '15 at 15:16
  • I appreciate your desire to help but you did not read my question fully which said: "But as soon as routes are defined not just from within the main app but also from packages I get in trouble because there's no way to say "and run this particular route last"." So I'm aware that "put this route last in code" would be an option, if it were an option, but for various reasons it is not. – seeekr May 30 '15 at 20:49
  • Aren't packages loaded before your main code? I have this route last and never had any problem with it, which package acts differently? – sdooo May 31 '15 at 11:06