Search code examples
routesmeteoriron-router

Meteor: Iron route not to the right route


So I've a navbar, and I've made my way to a sub dir in "Games" called "Cross" so, /games/cross. Now from that page, I'm trying to acess the Games page again from navbar but its showing /games/games... How do I fix this? I have the following...

Router.configure({
    layoutTemplate: 'layoutDefault'
});

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

Router.route('/contact', {
    template: 'contact'
});

Router.route('/games', {
    template: 'games'
});

Router.route('/games/cross', {
    action: function() {
        if(Roles.userIsInRole(Meteor.user(), ['normal' , 'admins'])) {
            this.render('cross')
        }
        else
            this.render('denied')
    }
});

Solution

  • If my understanding is correct, once you are in /games/cross page, you use your navbar to try to navigate back to the /games page, but your browser location bar now displays /games/games instead of just /games, and probably your router does not do anything? (or goes to whatever you have configured for route not found)

    It might rather be an issue in the links of your navbar: have you tried prepending a slash / at the beginning of your href attribute value, so that the link is relative to your domain, not to the current page?

    <a href="/games">Games</a>
    

    Instead of:

    <a href="games">Games</a>