question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug(router) unable to navigate to aux route in nested component

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

When defining an aux route in a nested route there is no way to enable this aux-component. Having this config:

[
  {path: 'dashboard', component: DashboardComponent}, 
  ...
  {path: 'tasks',  component: TasksComponent,
    children: [
      {path: '', component: TaskListComponent},
      ...
      {path: 'overview/:id', component: TaskOverviewComponent, outlet: "right"},
    ]
  },

and this code in TasksComponent html:

<div id="left">
  <router-outlet></router-outlet>
</div>

<div id="right">
  <router-outlet name="right"></router-outlet>
</div>

I can’t find a way to activate the right routeroutlet. I tried the following links:

http://localhost:4200/tasks(right:overview/1)
http://localhost:4200/tasks(right:./overview/1)
http://localhost:4200/tasks(right:/tasks/overview/1)

but no matter what I try I get:

Cannot match any routes: 'overview/1'
Cannot match any routes: './overview/1'
Cannot match any routes: '/tasks/overview/1'

What is the expected behavior?

It should be able to activate the aux-route

What is the motivation / use case for changing the behavior?

To be able to define aux-routes in nested routes, to be able to encapsulate all behaviour related to a use-case (“Tasks” in my case) in a dedicated module

Please tell us about your environment:

  • Angular version: current master (57473e72ec303e1e5b29cd717287755cd8a725a7)
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5 | Dart]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
alpalmerxactwarecommented, Nov 10, 2016

This is what I’m doing, and it seems to work.

const routeConfig = [
  { path:'', redirectTo: 'home', pathMatch: 'full'},
  {
    path:'home', component:HomeComponent,
    children: [
      { path:'', component:ContractsComponent },
      { path:'contracts', component:ContractsComponent },
      { path:'research', component:ResearchComponent},

      { path:'', outlet:'right-panel', component:PlanetComponent },
      { path:'contract/:id', outlet:'right-panel', component:ContractComponent }
    ]
   }
];

And my routerLink to use the right-panel which is placed in template of the “contracts” component.

[routerLink]="{outlets: {'right-panel':'contract/'+model.id}}"

Additionally, this also, allows the navigation by path:

import { Component, Input } from '@angular/core';
import { Contract } from '../../../../classes/Contract';
import { Router } from '@angular/router';

@Component({
  selector: 'contract-row',
  templateUrl: './contract-row.component.html',
  styleUrls: ['./contract-row.component.css']
})
export class ContractRowComponent {
  @Input() model: Contract;

  constructor(private router: Router) {}

  viewContract() {
    this.router.navigateByUrl('home/(contracts//right-panel:contract/'+this.model.id+')');
  }
}

Hopefully this his helpful. It was a serious pain in the neck to actually figure out how to get this working. It REALLY needs to be documented somewhere official.

3reactions
mikechamberlaincommented, Feb 26, 2017

This has been causing me pain for the last day, so here is a Plunkr demonstrating how to navigate to an auxiliary child route:

http://plnkr.co/edit/N1BxbCn3ZR8yd0lnHZBU?p=preview

The important thing to note (because of #10726) is that your parent path cannot be blank.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular - Use auxiliary routes in nested child components
I'm using Angular 2.1.2 with Router 3.1.2. parent.module import { NgModule } from '@angular/core'; ...
Read more >
Angular Router: Child Routes, Auxiliary Routes, Master Detail
We will cover both child and auxiliary routes, and we will learn how to setup the very commonly used Master Detail routing scenario....
Read more >
Angular Nested Auxiliary Routes (forked) - StackBlitz
Starter project for Angular apps that exports to the Angular CLI.
Read more >
RouterOutlet - Angular
Emits an attached component instance when the RouteReuseStrategy ... The router keeps track of separate branches in a navigation tree for each named...
Read more >
Working with Angular 14 Router - Techiediaries
How to import the necessary Angular built-in APIs to implement component routing and navigation,; How to create the routing module and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found