javascriptiron-routermeter

iron-router: How to load a route completely just as when hitting refresh after loading a route?


I have a sign-in method in my Meteor application that redirects users to different routes after login in to the system. Here is my method:

Meteor.loginWithPassword(emailVar, passwordVar, function (err) {
            if (err !== undefined) {
               // error handling code
            } else {
                if (!Roles.userIsInRole(Meteor.userId(), 'active')) {
                    return Router.go('account-deactivated');
                }
                if (Roles.userIsInRole(Meteor.userId(), 'pharmacist')) {
                    return Router.go('pharmacist-dashboard');
                }
                if (Roles.userIsInRole(Meteor.userId(), 'admin')) {
                    return Router.go('admin-dashboard');
                }
            }
        });

While this method works as expected, it produces some issues with my theme (AdminLTE) due to JavaScript loading problems (ex: app.min.js etc.). For example the sliding effects doesn't work on redirected page. But when I reload the page from the browser it starts to work as expected.

I know this is a separate issue that needs to be addressed. But if there is a way to completely reload a link in Meteor using iron-router it would be helpful. Specially when a page is transfered to a completely different user environment where a new set of JavaScript and CSS are used.

I went through the user documentations of iron-router but the fixes do not provide a solution.


Solution

  • Try using window.location.href to redirect.

    Using Router.go is merely loading the template for the route you are linking to, whereas using window.location.href is loading the url as if it was a link you just clicked (actual refresh).

    You'll need to use the actual url though, not the 'route name'.

    window.location.href = "http://yourapp.com/route/here";