Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route-component): provide matched path in route component #38

Merged
merged 1 commit into from
Aug 1, 2020

Conversation

meeroslav
Copy link
Collaborator

Provide the possibility to get the matched path in the RouteComponent, similar to params.
This enables the user to navigate back in the complex nested routes hierarchy with ease.

Example

app.component:

<router>
  <route path="/:username" [exact]="false">
    <app-user *routeComponent></app-user>
  </route>
  <route path="/" redirectTo="/johndoe"></route>
</router>

app.user:

<router>
  <route path="/family" [exact]="false">
    <app-family *routeComponent></app-family>
  </route>
  <route path="/">
    <div *routeComponent>
      ...some info about the user...
    </div>
  </route>
</router>
<a [linkTo]="path$ | async">{{ username$ | async }}</a>

app.user.ts:

export class AppUserComponent implements OnInit {
  username$: Observable<string>;
  path$: Observable<string>;

  constructor(
    private readonly routeParams$: RouteParams<{ username: string }>,
    private readonly routePath$: RoutePath<string>,
  ) { }

  ngOnInit(): void {
    this.path$ = this.routePath$;
    this.username$ = this.routeParams$.pipe(map(params => params.username));
  }
}

If we are at e.g. /janedoe/family/... we can easily go back to /janedoe.

@brandonroberts brandonroberts merged commit da7daed into angular-component:master Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants