router
router copied to clipboard
Router should get context path when starting up
Rather than having to set the base url and base href the router should pick up the context URL when the app starts and use that as the base for the routes.
What is the "context url"? I haven't seen that term before. Where can we derive it from?
Everything after the domain:
http://www.foo.com/some/context/url
And how does that relate to the base
tag?
See gitter... Someone was having a very hard time getting it to correctly route under the context.
If the app was running under /context1 rather than going to /context1/route1 it wanted to take them to /route1
In multi-app sites that could be part of a whole other app.
I haven't set up an Aurelia app to run below the root context but I don't see why the router can't handle that on its own.
Here's what he said he had to do to get it working. In the JSP he had to render this into the HTML:
and then when configuring the router:
var base = document.getElementByTagName(“base”)[0].href.replace(location.protocal + “//“ + location.host, “”); config.map([ { route: [base, base + "firstroute"] ... }, { route: [base + "secondroute"] ... }, ]);
None of this should be necessary.
I have got a workaround for this, but it's very clunky:
In the index file, add a base tag with the context path (be aware that this is JSP templating, NOT Aurelia templating). Don't forget the trailing slash!
<base href="${pageContext.request.contextPath}/" />
That will render out something like:
<base href="/ctxpath/" />
Or if you're at the root of the website:
<base href="/" />
Then in configureRouter(), do the following.
var base = document.getElementByTagName("base")[0].href.replace(location.protocol + "//" + location.host, "");
config.map([
{ route: [base, base + "firstroute"], ... },
{ route: [base + "secondroute"], ... },
{ route: [base + "thirdroute"], ... }
]);
It would be nice if Aurelia picks up this "base" from the base tag automatically, or we can enable it somehow (config.options.useBaseURL = true). Angular does this out of the box, by the way.
As it is now, all the route hrefs will have the context path stripped away.
(Sorry for the cross-posting)
We're happy to address this. It sounds like a good contribution that could come from the community. Is anyone interested in putting together a pull request for this?
I could take a look if you can point me to where I should start. I haven't messed with the router at all.
Start by looking at the history-browser library. It's relatively small and important to this issue.
Okay, will do
On May 20, 2016, at 2:25 PM, Rob Eisenberg [email protected] wrote:
Start by looking at the history-browser library. It's relatively small and important to this issue.
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/aurelia/router/issues/341#issuecomment-220682453
Be aware that the <base>
tag breaks SVG id's, so this should also work without it: https://github.com/aurelia/router/issues/382