angular2-routing

Get current route without parameters

落花浮王杯 提交于 2020-06-10 07:20:46
问题 I need to get my current route without params in Angular 2, I found a way to get the current route with params as follows: this.router.url and then split it: this.router.url.split(';')[0] But this looks as workaround, I think there should be better way? 回答1: parseTree from Router helps fetching the segments without any knowledge about url structure. import { Router } from '@angular/router'; ... constructor(private router: Router) {} ... const urlTree = this.router.parseUrl(url); const

angular2: how to get Full path on CanLoad guard while maintaining redirect url

孤街浪徒 提交于 2020-05-26 10:26:08
问题 I am using angular 2.4 version and router version "^3.4.10". I am trying to handle redirect url using auth guard service. When user hit url 'domain/assignment/3/detail' and if user is not login then user redirected to 'domain/login' page. and when user successfully login in to system then redirected to 'domain/assignment/3/detail' previous url which user tries to access. I have implemented CanLoad guard on assignment module. so when user tries to access url 'domain/assignment/3/detail' and if

How to use separate layout for login component in angular 2?

牧云@^-^@ 提交于 2020-05-25 06:27:07
问题 I am new in angular. I create a login component , it works fine fine but issue is that I want a separate layout of login from whole app. What changes required for that? I search on google but everyone give diff solution which not understandable also. const appRoutes: Routes = [ { path: 'alert/:id', component: AlertDetailComponent }, { path: 'alerts', component: AlertsComponent }, { path: 'dashboard', component: EriskDashboardComponent }, { path: '', redirectTo: '/dashboard', pathMatch: 'full'

Route to Same component with multiple Params

余生长醉 提交于 2020-05-16 20:11:52
问题 HTML Code <button (click)='getEnv("env")'>environment</button> <button (click)='getSchema("env","schema")'>schema</button> <button (click)='getEvent("env","schema","event")'>event</button> ROUTE FILE export const ROUTES: Routes = [ { path: '', redirectTo: 'home',pathMatch:"full" }, //{ path: 'home', component: HomeComponent }, { path: 'example', component: ExampleComponent }, { path: '**', component: HomeComponent }, { path: 'home/:env', component: HomeComponent,pathMatch:'full' }, { path:

Angular2 router config, prefix pathMatch does not work

时间秒杀一切 提交于 2020-05-10 11:11:10
问题 From what I understand from Angular2 router documentation, the routes config default pathMatch strategy is "prefix", "prefix" pathMatch strategy means the the app router only needs to look on the start of the url and match it with the proper route. Reference: https://angular.io/docs/js/latest/api/router/index/Routes-type-alias.html#!#matching-strategy That been said, with the below configurations I would assume that this route should load ExampleComponent if I navigate to /abcdefg . One

Remove the hash fragment from url permanently

∥☆過路亽.° 提交于 2020-04-12 18:18:12
问题 I use oauth authentication to login user. After the user has logged in, get taken from URL. URL like this: http://xxx/callback#access_token=xxx. then redirect to other page. I use this.router.navigateByUrl to redirect, the hash tag is removed but when I click other link,the hash fragment will show again. How can I remove the hash token fragment permanently? Example: after use login in //xxx/callback#access_token=xxx redirect to //xxx/home then click linkA, the url is //xxx/linkA#access_token

'router-outlet' is not a known element

送分小仙女□ 提交于 2020-04-07 13:52:56
问题 I have a mvc 5 project with a angular frontend . I wanted to add routing as described in this tutorial https://angular.io/guide/router. So in my _Layout.cshtml I added a <base href="/"> and created my routing in my app.module. But when I run this I get the following error: Error: Template parse errors: 'router-outlet' is not a known element: 1. If 'router-outlet' is an Angular component, then verify that it is part of this module. 2. If 'router-outlet' is a Web Component then add 'CUSTOM

'router-outlet' is not a known element

╄→尐↘猪︶ㄣ 提交于 2020-04-07 13:48:28
问题 I have a mvc 5 project with a angular frontend . I wanted to add routing as described in this tutorial https://angular.io/guide/router. So in my _Layout.cshtml I added a <base href="/"> and created my routing in my app.module. But when I run this I get the following error: Error: Template parse errors: 'router-outlet' is not a known element: 1. If 'router-outlet' is an Angular component, then verify that it is part of this module. 2. If 'router-outlet' is a Web Component then add 'CUSTOM

'router-outlet' is not a known element

谁都会走 提交于 2020-04-07 13:47:08
问题 I have a mvc 5 project with a angular frontend . I wanted to add routing as described in this tutorial https://angular.io/guide/router. So in my _Layout.cshtml I added a <base href="/"> and created my routing in my app.module. But when I run this I get the following error: Error: Template parse errors: 'router-outlet' is not a known element: 1. If 'router-outlet' is an Angular component, then verify that it is part of this module. 2. If 'router-outlet' is a Web Component then add 'CUSTOM

Is there better way to get ancestor route params in Angular2?

老子叫甜甜 提交于 2020-04-07 02:34:18
问题 I need to get param from route which is not parent and not even grand-parent, it's simply somewhere above, along the path to root. I am aware of approaches like shown in Angular 2: getting RouteParams from parent component or through shared service but situation which I put myself into (at least I think so) makes those not well suited for it. So here is what I got: I have lazily loaded sub-module which needs id from parent context. Situation more or less looks in routing configuration like