Skip to content
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

triggersEnter not run on FlowRouter.notFound #719

Open
davesierra opened this issue Jun 2, 2017 · 0 comments
Open

triggersEnter not run on FlowRouter.notFound #719

davesierra opened this issue Jun 2, 2017 · 0 comments

Comments

@davesierra
Copy link

Setting up routes, I generally use an auth function to make sure the user is logged in, if not redirect to '/' so they can login. However using FlowRouter.notFound does not trigger as expected:

function ifAuth(context, redirect) {
	console.log('ifAuth: check for user:', Meteor.userId());
	if (!Meteor.userId()) {
		console.log('No Meteor user, redirect to /');
		redirect('/');
	}
}


FlowRouter.notFound = {
	name: 'not-found',
	triggersEnter: [ifAuth],
	action: function() {
                console.log('page not found?')
		mount(MainLayoutContainer, {
			children: <NotFoundPage />
		});
	}
};

If I go to a route like '/asdf' it will log 'page not found' but not 'ifAutho: check for user:'

What I have to do instead is set a catch-all (like in most other routers) in order to run the ifAuth on a route not found:

FlowRouter.route('/*', {
	name: 'undefined',
	triggersEnter: [ifAuth],
	action: function(params, queryParams) {
		console.log('not a valid route')
	}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant