angular2-router

Angular2 - Extending router and Observable

两盒软妹~` 提交于 2019-12-01 06:30:47
问题 In angular2 rc2 with the router module v 3.0.0.6alpha, I extend the RouterOulet to check if the user is logged in before accessing the admin. So this is the code : @Directive({ selector: 'router-outlet' }) export class LoggedInRouterOutlet extends RouterOutlet { publicRoutes: Array<string>; private parentOutletMap: RouterOutletMap; private userService: UserService; private parentRouter: Router; constructor( parentOutletMap: RouterOutletMap, _location: ViewContainerRef, @Attribute('name') name

Using regex for path value of routes in angular2

六眼飞鱼酱① 提交于 2019-12-01 04:48:22
问题 I want to configure route for my angular2 application. My URL needs to be like this: http://domain_name/constant_value/variable_value/constant_value The url can be like following examples: http://localhost/myhouse/floor1/mirror http://localhost/myhouse/floor1/room1/mirror http://localhost/myhouse/floor1/room1/bathroom/mirror Here the routes /myhouse and /mirror are constant. But the middle part can be anything like /floor1 or /floor2/something/something/.... How can i define a route for that

Get the value returned by canActivate Method in Angular2 Route in a component?

北慕城南 提交于 2019-11-29 12:34:45
I have created a Auth Manager in Angular2 to restrict Component access directly . I am still new to angular and learning the concepts. I was able to restrict the user if the user name is not correct. But i am not able to use the value returned by the canActivate Method in my component to display a message in my front end. My AuthManager class import { Injectable } from '@angular/core'; import { CanActivate,Router,ActivatedRouteSnapshot,RouterStateSnapshot } from '@angular/router'; @Injectable() export class AuthManager implements CanActivate{ user = "user"; constructor(private router:Router){

Do I have to unsubscribe from ActivatedRoute (e.g. params) observables?

大憨熊 提交于 2019-11-28 07:58:20
I find many examples where ActivatedRoute Observables like params or url are subscribed but not unsubscribed. constructor(private route: ActivatedRoute) {} ngOnInit() { this.route.params // (+) converts string 'id' to a number .switchMap((params: Params) => this.service.getHero(+params['id'])) .subscribe((hero: Hero) => this.hero = hero); } Are the route objects and subscriptions destroyed automagically and newly created for every component creation? Do I have to care about unsubscribing from those Observable s? If not, can you explain what happens with the tree of ActivatedRoute objects in

Get the value returned by canActivate Method in Angular2 Route in a component?

余生长醉 提交于 2019-11-28 06:36:59
问题 I have created a Auth Manager in Angular2 to restrict Component access directly . I am still new to angular and learning the concepts. I was able to restrict the user if the user name is not correct. But i am not able to use the value returned by the canActivate Method in my component to display a message in my front end. My AuthManager class import { Injectable } from '@angular/core'; import { CanActivate,Router,ActivatedRouteSnapshot,RouterStateSnapshot } from '@angular/router'; @Injectable

What is the difference between ActivatedRoute and ActivatedRouteSnapshot in Angular4

痞子三分冷 提交于 2019-11-28 04:05:18
What is the difference between ActivatedRouteSnapshot and ActivatedRoute in Angular 4? It's my understanding that ActivatedRouteSnapshot is a child of ActivatedRoute , meaning that ActivatedRoute contains ActivatedRouteSnapshot . Incidentally, I tried running a Google search for an answer to this question, but I didn't find any of the search results to be understandable. Thank you! Since ActivatedRoute can be reused , ActivatedRouteSnapshot is an immutable object representing a particular version of ActivatedRoute . It exposes all the same properties as ActivatedRoute as plain values, while

How do I navigate to a sibling route?

▼魔方 西西 提交于 2019-11-27 12:17:32
Let's presume I got this router config export const EmployeeRoutes = [ { path: 'sales', component: SalesComponent }, { path: 'contacts', component: ContactsComponent } ]; and have navigated to the SalesComponent via this URL /department/7/employees/45/sales Now I'd like to go to contacts , but as I don't have all the parameters for an absolute route (e.g. the department ID, 7 in the above example) I'd prefer to get there using a relative link, e.g. [routerLink]="['../contacts']" or this.router.navigate('../contacts') which unfortunately doesn't work. There may be an obvious solution but I'm

Angular2 router, get route data from url, to display breadcrumbs

不问归期 提交于 2019-11-27 07:38:01
I am using angular2 router . To draw the breadcrumb of an url, lets say site.com/a/b/c/15 I do the following: Get the route of site.com/a/b/c/15 and get the pretty name associated to the route Get the route of site.com/a/b/c and get the pretty name associated to the route Get the route of site.com/a/b and get the pretty name associated to the route Get the route of site.com/a and get the pretty name associated to the route So lets say I do have the following routes: { path: 'a', component: A, data:{prettyName: 'I am A'}} { path: 'b', component: B, data:{prettyName: 'I am B'}}, { path: 'c',

What is the difference between ActivatedRoute and ActivatedRouteSnapshot in Angular4

好久不见. 提交于 2019-11-27 05:16:35
问题 What is the difference between ActivatedRouteSnapshot and ActivatedRoute in Angular 4? It's my understanding that ActivatedRouteSnapshot is a child of ActivatedRoute , meaning that ActivatedRoute contains ActivatedRouteSnapshot . Incidentally, I tried running a Google search for an answer to this question, but I didn't find any of the search results to be understandable. Thank you! 回答1: Since ActivatedRoute can be reused, ActivatedRouteSnapshot is an immutable object representing a particular

Do I have to unsubscribe from ActivatedRoute (e.g. params) observables?

二次信任 提交于 2019-11-27 02:07:01
问题 I find many examples where ActivatedRoute Observables like params or url are subscribed but not unsubscribed. constructor(private route: ActivatedRoute) {} ngOnInit() { this.route.params // (+) converts string 'id' to a number .switchMap((params: Params) => this.service.getHero(+params['id'])) .subscribe((hero: Hero) => this.hero = hero); } Are the route objects and subscriptions destroyed automagically and newly created for every component creation? Do I have to care about unsubscribing from