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

I am using Meteor 1.0 and iron: router. I am currently redirecting users with the following two route definitions:

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

How to determine the route for undefined routes (error 404)? For example, if the user goes to the URL "/ blablabla", I want him to be redirected to / 404, which would refer to the template.

+6
source share
2 answers

I used to have a specific route ( "/*" ), but it stopped working with my upgrade to Meteor 1.0, so I went looking for a better way, and I noticed that you can configure notFoundTemplate . This seems to be a trick for me. It uses layoutTemplate as the base and just populates yield with notFoundTemplate , which is exactly what I wanted.

 Router.configure({layoutTemplate: 'layout', notFoundTemplate: '404'}); 
+16
source

There is a dataNotFound iron-router dataNotFound that deals with undefined routes:

https://github.com/EventedMind/iron-router/blob/devel/Guide.md#plugins

0
source

Source: https://habr.com/ru/post/978055/


All Articles