angular-routing

Angular2 Router CanActivate, with Parameters?

老子叫甜甜 提交于 2020-01-03 13:01:18
问题 i've seen some issues on this specific issue. I'm lately only working on angular2 projects. Anyhow I'm rolling into an issue right now. In the deprecated Router I added my User Role in the data part of the route, I had overriden the routerOutlet so I could check this value before activating a route). Currently we can conform to the CanActivate Class/Interface row w/e we can call it. Right now I would like to be able to provide Permissions (which I've slapped into an Enum) to such CanActivate

Generically replace Angular 2 route parameter and navigate

谁说胖子不能爱 提交于 2020-01-03 08:09:10
问题 I'm building an Angular app in which most of the routes will pertain to a given project and contain a projectId. In the top navigation area will be a drop-down list of projects. When the user selects a project from the drop-down, it needs to navigate to the current route but with the projectId replaced with the new value. This is very similar to Angular navigate to url by replacing an existing parameter, however their accepted answer used query parameters; this needs to work on required route

Route without parameter value; Angular route redirect - Can I use redirectTo to parameter path?

假装没事ソ 提交于 2020-01-03 02:47:12
问题 I'm wandering if it is possible to redirect path: ' ' to path: ':id' ? Is there a way I can achieve this? Thank you. { path: 'folder', children: [ { path: '', redirectTo: ':id', pathMatch: 'full', }, { path: ':id', canActivate: [AuthGuard], component: DocumentsComponent, }, ] } 回答1: I found a way to redirect 'folder' route to 'folder/:id' with empty 'id' parameter: { path: 'folder', redirectTo: 'folder/', pathMatch: 'full', }, { path: 'folder', children: [ { path: ':id', canActivate:

Angular 2 — navigate through web pages without reloading a component that is common for those pages

元气小坏坏 提交于 2020-01-02 20:09:53
问题 Here you can find an example app: http://ivan-khludov.com/ This is my root component: import { Component } from '@angular/core'; @Component({ selector: 'root', template: ` <h1>My Dummy Angular App</h1> <router-outlet></router-outlet> <nav> <a routerLink="/section-1/1" routerLinkActive="active">Section 1 - Page 1</a> <span>||</span> <a routerLink="/section-1/2" routerLinkActive="active">Section 1 - Page 2</a> <span>||</span> <a routerLink="/section-2/1" routerLinkActive="active">Section 2 -

How to handle tenant subdomains in Angular 2 (router 3)

余生长醉 提交于 2020-01-02 10:01:40
问题 Trying to get tenant.app.com setup in Angular 2 (RC6, Router 3.0) Is there any documentation around how to do this? Almost everything I've seen starts with a base url = / and then parses the url from the base url. I need to have a www version for the non-signedin user and then tenant driven subdomains for all loggedin users 回答1: I think I have an approach that's working. getSubdomain() allows me to query the subdomain in app.component.ts on NgInit() and I can use that to scope the sign in for

Nested parameterized routes with ui-router in AngularJS

不想你离开。 提交于 2020-01-02 09:56:42
问题 I believe I'm on the right track with these terms, "nested parameterized routes", but haven't found what I'm looking for yet. My objective is to create intuitive routes for my API, something like the following example: /api/v1/project/list /api/v1/project/1/item/list /api/v1/project/1/item/1/edit /api/v1/project/2/item/3/delete It's relatively easy and clear how to setup project states, but not the item states within each project. { state: 'project' config: { url:'/project' } }, { state:

How to elegantly get full url from the ActivatedRouteSnapshot?

…衆ロ難τιáo~ 提交于 2020-01-02 00:50:13
问题 in some of my angular route guards, I want to set up the "next" path, to redirect to after successful login. So, the oridinary guard canActivate function signature looks like this: public canActivate(route: ActivatedRouteSnapshot): Observable<boolean> | boolean { // ...blah return true; } The route parameter is an instance of ActivatedRouteSnapshot. Previously to get the "next" URL I was just getting it from the route.url . This works just fine, as long as there are no children routes. My

AngularJS: Understanding $rootScope.$on('$routeChangeSuccess

你说的曾经没有我的故事 提交于 2020-01-01 10:03:19
问题 I am working on a login page, on success, it redirect to home page. By default I show login page this code: app.run(function($rootScope, $location) { $rootScope.$on('$routeChangeSuccess', function() { $location.url("/login"); }); }); Then after validating the user/pass details from the backend I take the user to the home page: $scope.login = function() { if ($scope.username === 'admin' && $scope.password === 'pass') { console.log('successful') $rootScope.$on('$routeChangeSuccess', function()

ngOnInit not being called after router.navigate

大憨熊 提交于 2019-12-30 17:25:16
问题 My Angular app is all of a sudden not calling ngOnInit() after router.navigation() which means my components do not load correctly. I thought it may have been due to some changes I made but reverting the changes did not resolve the issue. Example where normal navigation causes component not to load correctly; This page is navigated to by the following code listing: this.router.navigate(['/result', this.params.data._id]); : Reloading the page, the component is loaded correctly: Here are some

Angular2 get ActivatedRoute url

不羁的心 提交于 2019-12-30 04:06:28
问题 I want to get the url which comes from this: this.router.navigate(./somepath, { relativeTo: this.route }) this.route is of the type ActivatedRoute . I tried url: string = route.snapshot.url.join(''); but this gives an empty string. 回答1: You can use the activated route to get active URL. import { ActivatedRoute } from '@angular/router'; constructor( private activatedRoute: ActivatedRoute) { console.log(activatedRoute.snapshot['_routerState'].url); } 回答2: This should help: constructor(router: