angular2-routing

Angular2 routing based on subdomain?

房东的猫 提交于 2020-01-20 08:58:28
问题 I am trying to route in Angular2 Router based on the subdomain in a URL. For example if someone requests test.domain.com then they get the "test" route. I could not get router.navigate to work from ngOnInit without setting a timeout delay, but running the following from the constructor works. Would be interested if there was a cleaner solution ? {path: 'test', component: TestComponent} this._router.events.subscribe(event => { if (event.constructor.name === 'NavigationEnd' && window.location

Angular 2 and ASP.NET MVC 4 routing are not working together

亡梦爱人 提交于 2020-01-17 03:19:25
问题 I have implemented Angular2 in ASP.NET MVC 4 project. MVC routing is overriding Angular 2 routing. How can I handle both routing together? I have done following modification: _layout.cshtml: <base href="/"/> app.routing.ts: const route: Routes= [ {path: 'firstpage', component: firstComponent}, {path: 'secondpage', component: secondComponent} ] I have added below code above MVC default route in RouteConfig.cs: routes.MapRoute( name: "app1", url: "app1/{*url}", defaults: new { controller =

Angular2: How to test a component function that sometimes returns, sometimes routes?

允我心安 提交于 2020-01-15 10:22:21
问题 I'm still developing an app based on the Angular2 Heroes tutorial. At this point I have a component where the user makes an edit, clicks on Save and on success the user is spirited to the parent page (route "../"). If there is an error in saving then the routing doesn't occur, and the page displays the error information. The spiriting occurs in the component's save function: private gotoParent(): void { this.router.navigate(['../'], { relativeTo: this.route }); } public save(): void { this

Angular2: How to test a component function that sometimes returns, sometimes routes?

一世执手 提交于 2020-01-15 10:19:15
问题 I'm still developing an app based on the Angular2 Heroes tutorial. At this point I have a component where the user makes an edit, clicks on Save and on success the user is spirited to the parent page (route "../"). If there is an error in saving then the routing doesn't occur, and the page displays the error information. The spiriting occurs in the component's save function: private gotoParent(): void { this.router.navigate(['../'], { relativeTo: this.route }); } public save(): void { this

canActivate doesn't respond upon subscription change Angular 2 Router AngularFire2

半城伤御伤魂 提交于 2020-01-15 03:44:26
问题 I'm using AngularFire2. This is how I approached my AuthGuard service: canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { this.af.auth.subscribe((auth) => { if(auth == null) { this.router.navigate(['/login']); this.allowed = false; } else { this.allowed = true; } }) return this.allowed; } The above code works, except when I visit a guarded page directly (i enter URL in browser), it doesn't load the respective component after the subscription resolves to true. In

Angular2 RC.1 - Inject Router into unit test

廉价感情. 提交于 2020-01-13 10:47:27
问题 I'm writing my ng2 tests, and I'm running into some trouble injecting Router into my component for my test. The constructor for my component only takes one argument-- private router: Router . But, when I run my test case, I'm getting an error while it's trying to inject the Router. What am I doing wrong? Can anyone provide a working example? I'm using angular2-RC.1 Here's the error I'm getting: No provider for ComponentResolver! (Router -> ComponentResolver) Here's my test: import {describe,

angular 4 - routing within a component(child routes) not working properly

断了今生、忘了曾经 提交于 2020-01-12 15:17:18
问题 I recently started learning angular4 and currently working on routing in angular. I followed angular routing docs and started implementing some simple functionality of child routing. And I am stuck with it. Below is my code. Can anybody please tell what am I doing wrong? Dashboard module is imported into root module which has its own routes insite it. app/app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import {

Auto redirecting after n seconds using Angular 2

﹥>﹥吖頭↗ 提交于 2020-01-12 05:48:06
问题 I wanted to display a page for 'n' seconds and then redirect to another route. Came across a couple of stackoverflow posts (url1 and url2) about auto redirecting after 'n' seconds in Angular 1.x. But I m confused how to implement the same in Angular2? 回答1: You can inject and use Router from @angular/router and navigate in setTimeout . import { Router } from '@angular/router'; constructor(private router: Router) {} ngOnInit() { // do init at here for current route. setTimeout(() => { this

Angular2 Query Params Subscription Fires Twice

蓝咒 提交于 2020-01-11 18:46:35
问题 Trying to handle an OAuth login scenario where if the user lands on a page with authorization_code in the query string, we process the token and continue or if they land on the page without that, we check local storage for their existing token, make sure it's still valid and either redirect to login or continue, based on its validity. The problem is that where we're checking for the existence of the authorization_code query string param, the subscription is firing twice. The first time it is

How to handle multiple queryParams in Angular2

◇◆丶佛笑我妖孽 提交于 2020-01-11 06:13:10
问题 I'm trying to implement a filtering mechanism in a new Angular2 app, that would allow me to filter a list of entries in an array. The entries may have around 20 properties that could be filtered on. I have so far created a list of filters in one component and then a list component that is routed to, as a child. I then planned to pass the filters as queryParams through the router. Starting with just one filter this was fine: On the send side I had: this.router.navigate(['/findlist'],