The main url when starting the app on localhost is: http://localhost:9000/#, which is as expected. But then when navigating to a route (e.g. step-02 in the above example) the url changes to http://localhost:9000/#step-02. Should it not be http://localhost:9000/#/step-02? So the current version is missing a / after the #.
In aurelia V1 the additional / was added when using hash routing.
Further, if I want to use the router.load() function to change routes. Then this.router.load('step-02') will not work. The # needs to be added in this.router.load('#/step-02'). Why is this the case?
This is how @aurelia/router-lite currently behaves. I don’t know of any plans to change this.
The @aurelia/router behaves the way you expect it.
If you should decide to switch router, note that configuration options are slightly changed in @aurelia/router-lite compared with @aurelia/router. In @aurelia/router, your options would be
The option sameUrlStrategy is set on the configured routes or as a property in the component and is called reloadBehavior. (A configuration option on the router will be added in an upcoming release.)
In addition, the decorator is called @routes([ your routes here ]).
Let me know if you do decide to switch router and have any issues or questions.
Yes I would like to switch router. I can’t seem to find any documentation. Could you maybe share a link or an example?
Where do I import the router configuration from? import { RouterConfiguration } from '@aurelia/router or import { RouterConfiguration } from 'aurelia, or somewhere else
Ah ok I see. Thank you. Unfortunately, after installing @aurelia/router I get the following error:
Uncaught Error: Conflicting @aurelia/metadata module import detected. Please make sure you have the same version of all Aurelia packages in your dependency tree.
@jwx thanks for all of the help so far. I have got two more questions:
I can’t seem to get the string Aurelia out of the title. So page title would always be Component Title | Aurelia. Trying this doesn’t seem to do anything.
When I navigate to that component using router.load('xyz') I would like to add in some logic in the components load hook so that depending on some condition, it knows which child route it should load.
Changing the title doesn’t show the change until a new navigation is made (or a new tab is opened). I’m aware of it, but since it, as far as I know, is a minor inconvenience I haven’t fixed it yet (other things have had higher priority). Let me know if you’re unable to change the title at all, even after opening a new tab.
As for your child routes use case, there’s details that I’m missing, but maybe by adding an au-viewport in xyz.html and then have something like:
load() {
if(a) this.router.load('child-1', { context: this });
if(b) this.router.load('child-2', { context: this });
if(c) this.router.load('child-3', { context: this });
}
in xyz.ts. Let me know if this doesn’t fit your use case.