Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In meteor, using iron:router how to redirect user to page 404 if the path is not defined?

Tags:

meteor

I use Meteor 1.0 and iron:router. I currently redirect users with the following 2 routes definitions:

Router.route('/', function () {
  this.render('home_page');
});

Router.route('/about', function () {
  this.render('about');
});

How can I define a route for undefined routes (error 404) ? For instance, if a user go to the url "/blablabla", I want him to be redirected to /404 which would refer to a template.

like image 632
JLavoie Avatar asked Nov 11 '14 23:11

JLavoie


1 Answers

I used to have a catch-all route defined ("/*") but that stopped working with my update to Meteor 1.0, so went looking for a better way and I noticed that you can configure a notFoundTemplate. That seems to do the trick for me. It use the layoutTemplate as the base and just fills in the yield with the notFoundTemplate which is exactly what I wanted.

Router.configure({layoutTemplate: 'layout', notFoundTemplate: '404'});
like image 172
Larry Maccherone Avatar answered Sep 28 '22 08:09

Larry Maccherone