angular2-routing

Angular: How to determine active route with parameters?

扶醉桌前 提交于 2019-12-17 20:34:25
问题 I've read this question about how to determine the active route, but still it's not clear to me how to determine an active route with paramaters? Right now I'm doing it like this: <a [routerLink]="['/Profile/Feed', {username: username}]" [ngClass]="{active: getLinkStyle('/profile/john_doe/feed')}"> Feed for {{username}} </a> And inside my component: getLinkStyle(path:string):boolean { console.log(this._location.path()); // logs: '/profile/john_doe/feed' return this._location.path() === path;

Update parent component title from routed child component in Angular 2 [duplicate]

吃可爱长大的小学妹 提交于 2019-12-17 20:23:49
问题 This question already has answers here : how to change page title in angular2 router (13 answers) Closed 3 years ago . I'm working my way through the Angular 2 documentation on routing. I have a sample application which shows two components which are routed and hooked up to navigation links. Here is a Plunker demonstrating the behaviour. It's built using Angular 2 in Typescript. Here is the main 'app.component.ts' code: import {Component} from 'angular2/core'; import {RouteConfig, ROUTER

Can you use @ViewChild() or similar with a router-outlet? How if so?

▼魔方 西西 提交于 2019-12-17 20:04:04
问题 I repeatedly run into a situation where I'd like to access a child component existing on the other side of a router outlet rather than a selector: Like: <router-outlet></router-outlet> NOT: <selector-name></selector-name> This conflicts with the ViewChild functionality as I know it, yet it seems like my component should be able to see and interact with what's inside that router-outlet just as easily as with what's inside a selector-tag. For instance I tried this: export class

CanDeactivate confirm message

你离开我真会死。 提交于 2019-12-17 19:39:15
问题 I've implemented a CanDeactivate guard to avoid user leave the page during the upload and it works. The problem is that my message is always a default message (in dutch because of the browser language) and, even setting a message myself, still show the same default confirm window. I would like to write my own message (actually I have a modal that I want to show, but first I would like to see working just with my simple message) Any ideas what could it be? Am I missing something? Thanks in

Angular2 way of converting plain text to url (anchor links)

≯℡__Kan透↙ 提交于 2019-12-17 18:52:10
问题 I sometimes have a component that can receive text like this: text www.website.com But I would like to convert it to a url if it is a link. Like this. text www.website.com I read this SO answer that suggests using 3rd party libs such as anchorme. Is there anywway to do it the angular2 way? 回答1: There are numerous problems with using simple regexes to modify HTML content. Here's an approach that uses the linkifyjs module, which you need to npm install . Do notice that the input is considered

Retrieve hash fragment from url with Angular2

。_饼干妹妹 提交于 2019-12-17 18:25:56
问题 Given this url structure (over which I have no control), how can I retrieve the hash fragment using Angular2? http://your-redirect-uri#access_token=ACCESS-TOKEN My router does route to the correct component, but everything after oauth get scrapped and I can't find the hash fragment in request.params or location.path. Doomed?? Router config: @RouteConfig([ {path: '/welcome', name: 'Welcome', component: WelcomeComponent, useAsDefault: true}, {path: '/landing/oauth', name: 'Landing', component:

Angular2 router: how to correctly load children modules with their own routing rules

别等时光非礼了梦想. 提交于 2019-12-17 18:01:19
问题 here is my Angular2 app structure: Here is part of my code. The following is the main module of the Angular2 app, that imports its routing rules and a child module ( EdgeModule ) and uses some components related to some pages. app.module.ts @NgModule({ declarations: [ AppComponent, PageNotFoundComponent, LoginComponent ], imports: [ ... appRouting, EdgeModule ], providers: [ appRoutingProviders, LoginService ], bootstrap: [AppComponent] }) export class AppModule { } Here is the routing rules

How to set Bootstrap navbar “active” class in Angular 2?

浪尽此生 提交于 2019-12-17 17:35:03
问题 How can I set Bootstrap navbar "active" class in Angular 2? I only found Angular 1 way. When I go to About page, add class="active" to About , and remove class="active" on Home . <ul class="nav navbar-nav"> <li class="active"><a [routerLink]="['Home']">Home</a></li> <li><a [routerLink]="['About']">About</a></li></li> </ul> Thanks 回答1: If you use the new 3.0.0. component router ( https://github.com/angular/vladivostok ) you can use the routerLinkActive directive. No further javascript required

return boolean instead of subscribe to canActivate

一曲冷凌霜 提交于 2019-12-17 16:48:06
问题 I have a component protected with canActivate guard. The Authguard in the checkLogin function subscribes from an observable but I do not know how to return a boolean value from it to canActivate. guard.service.ts canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { let url: string = state.url; return this.checkLogin(url); } public checkService:boolean; checkLogin(url: string):boolean { return this.loadAppSettings().subscribe(res=>{ console.log(this.checkservice);

Hash Location Strategy in Angular 2

ⅰ亾dé卋堺 提交于 2019-12-17 16:47:11
问题 I'm trying to create an application with hash location strategy, but it does not add the hash to the url. For instance when I click on a button associated with { path: '/polls', name: 'Polls', component: PollsComponent } it loads the page with this url : localhost:3000/polls. What do I have to change to get the hash location strategy? Why do I have to set the default base url if I want to use hash location strategy? This is the routing in the app.component.ts where all the routing is defined: