Closed bengladwell closed 9 years ago
So the issue here is that navigate
expects the root prefix to be removed but the links that are inserted into the html content do have this?
Yeah.
So you might have routes like:
routes: {
"posts/": "posts"
}
If you initialize Backbone.history with a root like "rootpath", you do want the url helper to produce hrefs like href="/rootpath/posts/"
so that your hrefs are correct for server-side rendering. However, when navigate
tries to match /rootpath/posts/
against posts/
, it will miss.
So, I'm suggesting that _anchorClick should strip the root before calling navigate
when applicable.
Also, thanks for spending a good part of your Thanksgiving weekend working on Thorax. That's really awesome.
This should hopefully be fixed in the next release.
I submitted PR #398. It is admittedly a confused PR. I should have opened an issue first. I'll close the PR since I'm not even really suggesting that solution anymore.
Does the issue raised in the PR make sense?
I originally commented: If you initialize Backbone.history with a root like "/path/" and pass a fragment like "/articles" to the url helper, you should get "/articles", not "/path/articles" [as a link href]. If you define a root, your route definitions do not include that root.
Later I realized that the root should be included in the hrefs so that you get proper hrefs that can be rendered by the server. In my code, I am addressing this by overriding _anchorClick like this:
This block:
strips out the root before navigating if the href begins with the root.
Does this seem like a reasonable solution?