My current configuration:
const routes: Routes = [ { path: '', component: NavComponent, outlet: 'nav' }, // (1) { path: '**', component: NavComponent, outlet: 'nav' } // (2) ];
It works. NavComponent always displayed on nav output. In particular, it works for all of the following types of URLs:
http://example.com/foo(nav:bar) // (a) non-empty path in nav --> (2) http://example.com/foo(nav:) // (b) empty path in nav --> (2) http://example.com/foo // (c) no nav at all --> (1)
Note that the router maps different routes to these URLs:
(1) used for (c)(2) used for (a) and (b)
This is why the NavComponent instance NavComponent destroyed and recreated every time location changes say (c) to (a) . And this is what I need to prevent. I need to save my instance due to its state, animation, etc. As far as I understand, this is possible only if the same route is used for all URLs, however I cannot find a way to do this. If I remove (1) , URLs such as (c) will stop showing NavComponent in nav . Apparently ** does not match such URLs (I'm not sure why).
You can see it in action here: https://stackblitz.com/edit/angular-ptzwrm
What is the right solution here?
I am currently redefining UrlSerializer to add (nav:) to URLs like (c) before parsing, but this seems like a hack.
angular angular-router
thorn
source share