angular2-routing

Angular2 RC1 child routes defined but not recognized

帅比萌擦擦* 提交于 2019-12-04 11:05:42
问题 What used to work for beta /... is no longer working. With the new new RC1 router, how do I do the child routing? Folder structure app |--home/ | |--home.component.ts |--login/ | |--login.ts |--appShell/ | |--app.component.ts |--apps/ |--hero/ |--hero-shell.component.ts |--horees.component.ts |--hero-detail.component.ts The planned navigation is app.component -> home.component -> heroshell.component -> heroes.component app.component.ts routes @Routes([ { path: '/heroshell', component:

Angular2: how to “reload” page with router (recheck canActivate)?

蹲街弑〆低调 提交于 2019-12-04 10:58:53
问题 I have routers with canActivate: [ AuthGuard ] and validation inside AuthGuard How to force check canActivate in same router url ? For example: Current route is /admin and I have got event like session expired . I have session check in AuthGuard but this check activates only when I execute .navigate(...) . How to force run canActivate in same location? I've tried: this.router.navigate([ this.router.url ]); but angular checks same location and do nothing. p.s. I can locate to "login page" or

History forward / backward button doesn't work with angular 2 router

假如想象 提交于 2019-12-04 10:22:26
History( Push State) forward / backward button doesn't work with angular 2 router.I have tested this in Chrome and Firefox both. Forward button works never and Backward button works only for 2 steps than UI doesn't respond according backward button. I have following code. app.component.ts import { Component } from '@angular/core'; import { ROUTER_DIRECTIVES, Routes } from '@angular/router'; import { CrisisListComponent } from './crisis-list.component'; import { HeroListComponent } from './hero-list.component'; import { Login } from './login'; @Component({ selector: 'my-app', template: ` <h1

Angular 2 roles and permissions

我们两清 提交于 2019-12-04 09:33:47
I have used angular2 and laravel 5.3 in my project. in laravel when user logged in server will be send the permissions of the user to handle authorization in angular. so I wrote a guard to protect routes from users that cannot access. here is my guard class code: export class AccessGuard implements CanActivate{ permissions; currentRoute; constructor(private authService:AuthService,private router:Router){ this.permissions = this.authService.getPermissions(); } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot){ return this.checkHavePermission(state.url); } canActivateChild

angular2 router.navigate inside auth0 callback

∥☆過路亽.° 提交于 2019-12-04 09:19:42
I am having an issue rendering a template after calling router.navigate inside a callback for auth0lock loginComponent.ts import {Component, Inject} from 'angular2/core'; import {Router, ComponentInstruction} from 'angular2/router'; import {Auth} from '../auth'; declare var Auth0Lock; @Component({ selector: 'login', templateUrl: '/tpls/login/login.html' }) export class LoginComponent { private lock = new Auth0Lock('xxx', 'xxx.auth0.com'); constructor(@Inject(Router) private router: Router, @Inject(Auth) private auth: Auth) { } logError = (err) => { console.log(err); } loginSuccess = (data) =>

How do you inject an angular2 service into a unit test? (RC3)

梦想与她 提交于 2019-12-04 08:47:46
I am using RC3 . I am implementing the new Angular2 router as documented here: https://angular.io/docs/ts/latest/guide/router.html Everything works fine but I am having problem in unit testing. Specifically, I cannot inject Angular2 services into my unit tests. My relevant component code is: import {Component} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; @Component({ templateUrl: ... styleUrls: ... }) export class Route1DetailComponent { constructor(private route:ActivatedRoute) { console.log(route); } } my unit test looks like: import { expect, it, iit, xit, describe,

How to pass and get parameter with routerLink in Angular 2?

孤街浪徒 提交于 2019-12-04 08:40:41
问题 I want to pass a value with url using routerLink. And read that value on another page. Like I have product list. On select of first record the id of that record pass to product detail page. After read that productId I want to show detail of that product. So How can I pass and get the parameter? 回答1: I'm assuming you have some code like this: { path: 'product/:id', component: ProductDetailComponent } in ProductList template <a [routerLink]="['/product', id]">Home</a> or <a [routerLink]="['

Angular. Router DI not working when using APP_INITIALIZER

懵懂的女人 提交于 2019-12-04 08:30:29
I'm preloading app configuration from server with APP_INITIALIZER in following way, AppModule : providers: [ ConfigService, { provide: APP_INITIALIZER, useFactory: configServiceFactory, deps: [ConfigService], multi: true } ], Then, ApiService injected manually from ConfigService : @Injectable() export class ConfigService { private api: ApiService; public constructor( private injector: Injector ) { // Avoid cyclid dependencies, inject manually: this.api = injector.get(ApiService); } And finally router is undefined when injected in ApiService import { Http, Headers, RequestOptionsArgs, Response

angular2: CanDeactivate guard

怎甘沉沦 提交于 2019-12-04 08:26:36
问题 I've created a CanDeactivate guard which returns an observable and it's applied to a component which is loaded in a inner nested router-outlet. Should this guard be called whenever one tries to navigate to another url? I'm asking this because this is not happening in my case. In my case, the guard will only get called for the first "different" URL. Let me try to explain it with an example. Assume I'm always returning false and I'm trying to navigate to different urls from the same component:

“No provider for AuthGuard!” using CanActivate in Angular 2

旧巷老猫 提交于 2019-12-04 08:15:45
问题 EDIT : Obviously this is outdated, now you provide your guard at the providers array in an NgModule. Watch other answers or official documentation for more information. bootstrapping on a component is outdated provideRouter() is outdated as well I'm trying to setup Authentication in my project, using a login and AuthGuard from the Angular2 guide : https://angular.io/docs/ts/latest/guide/router.html I'm using the release : "@angular/router": "3.0.0-beta.1". I'll try to explain as much as