- <a [routerLink]=['/widgets', widget.id]"> is a good example of passing an id as a second route chunk at a link.
- .forRoot will only get set and used once while .forChild may be reset from feature module to feature module. Using .forChild will not "reregister the router service" which would be problematic. Routes that exist randomly in a .forChild that are not mentioned at the .forRoot are legit in the big picture assuming that the feature module with the .forChild is referenced by the outermost God module. Note that .forChild route paths take precedence/priority over the .forRoot route paths if the .forRoot paths are just jammed in the outmost God module and this is probably for the best. If you make a dedicated module for the routing, then this module should probably go last in the imports (at the outermost God module) to achieve the same effect. Failing to do so can allow a wildcard route in the .forRoot stuff to catch a legitimate route for a .forChild crafting.
- I redirectTo in Angular's routes make for a good way to accommodate URLs for old links to changed routes. If a redirectTo redirects to a route with a second redirectTo the second hop does not get made unfortunately.
- If a link parameters array at a routerLink attribute at a tag in a template contains one one element, the square brackets around both the "routerLink" attribute directive designation and the value may be removed. Also don't put single quotes inside of the double quotes at the assignment. This is the shortcut syntax for routerLink.
- this.router.navigateByUrl('/foo'); varies from this.router.navigate('/foo'); as the former will drop any secondary routes. Herein router is the Router imported from '@angular/router' and note that the absence of square brackets wrapping the '/foo' paths is supposedly perfectly legit as a shortcut instead of an array of one item. Honestly, I could not get it to work today. It seems to work for .navigateByUrl but not .navigate alone.
- At http://www.example.com/foo(bar:baz) the stuff in parenthesis is the secondary route.
Wednesday, November 28, 2018
some Angular routing stuff from today
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment