Skip to content Skip to sidebar Skip to footer

Angular 4 - Update Route Without Appending Another Outlet's Route To Url

I have a situation in Angular 4.0.3 where I have two 's on a page.

Solution 1:

Unless there is some trick I'm not aware of ... I don't think you can. The address bar is what maintains the route state. So without the secondary outlet information in the address bar, the router won't know how to keep the correct routed component in the secondary outlet.

You could try overriding the navigateByUrl method as shown here: http://plnkr.co/edit/78Hp5OcEzN1jj2N20XHT?p=preview

exportclassAppModule {   constructor(router: Router) {
    const navigateByUrl = router.navigateByUrl;

    router.navigateByUrl = function(url: string|UrlTree, extras: NavigationExtras = {skipLocationChange: false}): Promise<boolean> {
      return navigateByUrl.call(router, url, { ...extras, skipLocationChange: true });
    }   } }

You could potentially add logic here then to check which routes you need to do this on.

Post a Comment for "Angular 4 - Update Route Without Appending Another Outlet's Route To Url"