angular-router

Accessing Route data in root component, route data is empty

白昼怎懂夜的黑 提交于 2019-12-01 16:43:09
问题 My problem is that I have a lang.component loaded with <router-outlet> . What I need is to access ActivatedRoute params in the root component which is app.component but all route data there is empty. I am able to access route data from lang.component normally by subscribing to params link to code that you can run: https://plnkr.co/edit/gTXPUb6TvatbMyOPPRKj If you run the code and open your console you can see two logs. It shows you what the problem is. Please help. Thank you. 回答1: Instead of

Angular 2+: How to access active route outside router-outlet

风格不统一 提交于 2019-11-30 22:36:53
问题 I have an Angular 5 application. I have the following code in my app component. I want to hide navbar and topbar for particular routes. Is it possible to get currently activated route in app.component.ts ? if so, How ? If not possible, is there any solution to resolve this ( using guards or whatever else ... )? Also keep in mind that it should be reactive. when i switch to another route sidebar and navbar should show again. 回答1: Try this: in app.component.ts import { Component } from '

How to implement multi-level routing in Angular?

↘锁芯ラ 提交于 2019-11-30 10:03:02
I'm working on a little project of mine in order to learn something more about Angular, but I really cannot figure out how to implement a multi-leveled routing. I've read the documentation about the new release of the Router Component and also some other topics on StackOverlfow ( first , second , third ), but I cannot find a solution to my problem. Let's consider the following app structure , without considering the Test and Test2 blocks. And let's consider the components of my app as following: main.ts import { bootstrap } from '@angular/platform-browser-dynamic'; import { MyAppComponent }

Get route parameters in component

蓝咒 提交于 2019-11-30 09:02:39
问题 I am working on the Angular-6 project. I have many child routes for my application. One of them is as follow: const routes: Routes = [ { path: 'innovation-track/:innovation-track-id', component: InnovationTrackComponent, children: [ { path: 'sprint', component: ScrumBoardComponent } ] } ]; I want to get innovation-track-id value from URL in my ScrumBoardComponent . I know I can get this by doing following: constructor(private _route: ActivatedRoute) { } //somewhere in method this._route

How to get all route params/data

自闭症网瘾萝莉.ら 提交于 2019-11-30 03:58:38
Given a route config { path: '/root/:rootId', children: [{ path: '/child1/:child1Id', children: [{ path: '/child2/:child2Id component: TestComponent }] }] } In TestComponent how can I easily get all route params. I'm wondering if there is an easier way than let rootId = route.parent.parent.snapshot.params; let child1Id = route.parent.snapshot.params; let child2Id = route.snapshot.params; This seems overly redundant especially if I'm watching the route params observable instead of access the param through the route snapshot. This method also seems fragile since it would break If I moved any any

Angular 5 Scroll to top on every Route click

一世执手 提交于 2019-11-29 19:50:32
I am using angular 5. I have a dashboard where I have few sections with small content and few sections with so large content that I am facing a problem when changing router while going to top. Every time I need to scroll to go to top. Can anyone help me to solve this issue so that when I change the router my view always stay at the top. Thanks in advance. A router outlet will emit an activate event any time a new component is being instantiated, so (activate) event could be to scroll (for example) to the top: app.component.html <router-outlet (activate)="onActivate($event)" ></router-outlet>

How to implement multi-level routing in Angular?

ε祈祈猫儿з 提交于 2019-11-29 15:34:56
问题 I'm working on a little project of mine in order to learn something more about Angular, but I really cannot figure out how to implement a multi-leveled routing. I've read the documentation about the new release of the Router Component and also some other topics on StackOverlfow (first, second, third), but I cannot find a solution to my problem. Let's consider the following app structure , without considering the Test and Test2 blocks. And let's consider the components of my app as following:

Get route parameters in component

旧时模样 提交于 2019-11-29 11:15:16
I am working on the Angular-6 project. I have many child routes for my application. One of them is as follow: const routes: Routes = [ { path: 'innovation-track/:innovation-track-id', component: InnovationTrackComponent, children: [ { path: 'sprint', component: ScrumBoardComponent } ] } ]; I want to get innovation-track-id value from URL in my ScrumBoardComponent . I know I can get this by doing following: constructor(private _route: ActivatedRoute) { } //somewhere in method this._route.snapshot.parent.paramMap But, I want to fetch innovation-track-id value in any component, doesn't matter if

Custom RouteReuseStrategy for Angular's child module

故事扮演 提交于 2019-11-29 00:29:45
I want to use this custom route reuse strategy for just one module: export class CustomRouteReuseStrategy extends RouteReuseStrategy { public shouldDetach(route: ActivatedRouteSnapshot): boolean { return false; } public store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void {} public shouldAttach(route: ActivatedRouteSnapshot): boolean { return false; } public retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle { return null; } public shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean { return true; } } So I've passed into

How to get all route params/data

末鹿安然 提交于 2019-11-28 22:50:17
问题 Given a route config { path: '/root/:rootId', children: [{ path: '/child1/:child1Id', children: [{ path: '/child2/:child2Id component: TestComponent }] }] } In TestComponent how can I easily get all route params. I'm wondering if there is an easier way than let rootId = route.parent.parent.snapshot.params; let child1Id = route.parent.snapshot.params; let child2Id = route.snapshot.params; This seems overly redundant especially if I'm watching the route params observable instead of access the