angular2-router3

How to pass a parameter to routerLink that is somewhere inside the URL?

早过忘川 提交于 2019-11-30 06:13:21
问题 I know I can pass a parameter to routerLink for routes such as /user/:id by writing [routerLink]="['/user', user.id]" but what about routes such as this one: /user/:id/details Is there a way to set this parameter or should I consider a different URL scheme? 回答1: In your particular example you'd do the following routerLink : [routerLink]="['user', user.id, 'details']" To do so in a controller, you can inject Router and use: router.navigate(['user', user.id, 'details']); More info in the

How to handle hash fragments from oauth redirect urls in Angular2 rc3 routing

戏子无情 提交于 2019-11-29 18:27:45
问题 I'm trying to find a way to handle setting up an Angular2 Typescript route (using the 3.0.0-alpha.8 router) that will handle routes that begin with hash fragments. The app I'm working on handles all login externally (something I have no control over) through a rails backend with oauth2. Redirecting users to the external login page works fine but when the redirect url, always some form of http://localhost:4200#access_token=TOKEN (where TOKEN is a series of numbers and letters) is sent back but

No provider for ActivatedRoute - Angular 2 RC5

偶尔善良 提交于 2019-11-29 13:10:50
After upgrading to Angular 2 RC5 (from RC4) it seems I can no longer inject ActivatedRoute into my components. ORIGINAL EXCEPTION: No provider for ActivatedRoute! Here's the relevant piece of code: import { Component } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; declare var module: { id: string; }; @Component({ moduleId: module.id, selector: 'mds-app', templateUrl: 'app.component.html', styleUrls: [ 'app.component.css' ], directives: [] }) export class AppComponent { constructor(private _route: ActivatedRoute) { this._route.params.subscribe(params => console.log(

Return Observable in canDeactivate not working

不打扰是莪最后的温柔 提交于 2019-11-29 10:51:15
I have a confirm/cancel modal dialog that pops up when a user leaves a route. I do this by using a guard with the canDeactivate method. However I want canDeactivate to wait until it gets a response from the modal before returning anything. I have tried to do this by returning an observable but it is not working. canDeactivate(): Observable<boolean> | boolean { if(this.isFormStarted()) { this.formService.showExitModal(true); return this.formService.getModalSelectionObservable(); } else { return true; } } Nothing is happening when I click confirm even though I can see that the observable is

Angular2 Routing : Loading twice

空扰寡人 提交于 2019-11-29 10:01:18
I am using Angular2 with routing and my page is showing duplicate content on initial load. Once i click any Link(Page1 or Page2) everything works perfect(there is no more duplicate content). Why am i getting the duplicate content on initial load and what do i need to have it display once only Screen Shot index.html <html> <head> <base href="/"> <title>Angular QuickStart</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> <link rel="stylesheet"

RC5 : Lazy loading of NgModule in different router-outlet

一个人想着一个人 提交于 2019-11-29 07:46:29
I'm using RC5's NgModule to do dynamic route loading. My app has two depth level. I have routes like : app/login app/dashboard/module1 app/dashboard/module2 etc... Each deph level has it's own router-outlet so I can define custom layout at each level. i.e. login and dashboard are displayed in app router-outlet while module1 and module2 are displayed in dashboard router-outlet. What is the configuration to load dynamically each route on demand ? Here is a minimal working example of dynamic loading accoss NgModules and router-outlet. app.module.ts @NgModule({ declarations: [AppComponent],

How to pass a parameter to routerLink that is somewhere inside the URL?

醉酒当歌 提交于 2019-11-28 15:55:42
I know I can pass a parameter to routerLink for routes such as /user/:id by writing [routerLink]="['/user', user.id]" but what about routes such as this one: /user/:id/details Is there a way to set this parameter or should I consider a different URL scheme? Wojciech Kwiatek In your particular example you'd do the following routerLink : [routerLink]="['user', user.id, 'details']" To do so in a controller, you can inject Router and use: router.navigate(['user', user.id, 'details']); More info in the Angular docs Link Parameters Array section of Routing & Navigation Rıdvan Maybe it is really late

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

Angular2 Routing : Loading twice

主宰稳场 提交于 2019-11-28 03:29:20
问题 I am using Angular2 with routing and my page is showing duplicate content on initial load. Once i click any Link(Page1 or Page2) everything works perfect(there is no more duplicate content). Why am i getting the duplicate content on initial load and what do i need to have it display once only Screen Shot index.html <html> <head> <base href="/"> <title>Angular QuickStart</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet"

RC5 : Lazy loading of NgModule in different router-outlet

旧巷老猫 提交于 2019-11-28 01:22:44
问题 I'm using RC5's NgModule to do dynamic route loading. My app has two depth level. I have routes like : app/login app/dashboard/module1 app/dashboard/module2 etc... Each deph level has it's own router-outlet so I can define custom layout at each level. i.e. login and dashboard are displayed in app router-outlet while module1 and module2 are displayed in dashboard router-outlet. What is the configuration to load dynamically each route on demand ? 回答1: Here is a minimal working example of