Confirmation of Iron Router process

I’m using Iron Router for my web app. I have observed some behaviour with it and need confirmation that I am doing things correctly.
If I click an link that has a basic href like href="/home" then the browser doesn’t seem to visually refresh (which is what I would expect from Iron Router). However, if I click a link that has href="Javascript:location.href='/home'" or a link that runs location.href from a Template.events block the browser physically refreshes. Am I right in saying that Iron Router does not intersect calls made by locaiton.href to ensure that it doesn’t have to refresh the browser to navigate?

You mean whether it does or does not intercept calls to window.location.href? No, it does not intercept those and do something other than what the browser would do regularly – so yes, the browser then refreshes the page, reloads it completely from the server.*
For all regular link tags iron:router does indeed intercept the clicks on those and uses its client-side route information to first try and resolve the url to a client-side route. Only if it can’t find any it will request that url from the server, i.e. reload the page (I think! But maybe it just makes a request to the server and then replaces content anyway, I am not sure, it may not be that clever).

EDIT:
*: Because we still need some way of working around iron:router just in case we need it, and we don’t usually need location.href for regular purposes, so it does not override that behavior, which is perfect.

1 Like