angular-router

Angular lazyload child routes with outlet

让人想犯罪 __ 提交于 2019-12-07 07:13:25
I have tried to reproduce my error in a stackblitz What I try to accomplish I am trying to have a route with a dynamic parameter, and have sub routes of that parameter. I want this module to be lazyloaded. I have made a working solution for the dynamic parameter using the :id definition in the route definition. I want the child routes to output in a different router-outlet. Specifically I want a component ( UserComponent ) loaded on the route user/:username - if the path is empty after the :username I want to load UserDefaultContentComponent in the router defined inside the UserComponent - If

Angular Service singleton constructor called multiple times

我的未来我决定 提交于 2019-12-07 02:28:39
问题 I am trying to use an app-wide service (UserService) that stores authenticated user details. I have set up some routes but found that UserService is instantiated per route. I want them to share the same UserService. I have created a CoreModule containing TestService as provider and imported it into AppModule. core.module.ts: import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { TestService } from '../test.service'; @NgModule({ imports: [

router.navigate with query params Angular 5

安稳与你 提交于 2019-12-06 17:38:10
问题 I'm having an issue with routing to a route with query params I have a function like so goToLink(link) { this.router.navigate([`${link.split('?')[0]}`, { queryParams: this.sortParams(link)}]); } and this function sortParams(link) { let queryParams = url.split('?')[1]; let params = queryParams.split('&'); let pair = null; let data = {}; params.forEach((d) => { pair = d.split('='); data[`${pair[0]}`] = pair[1]; }); return data; } okay so basically what Is happening I have a function called

Angular router: ignore slashes in path parameters

风格不统一 提交于 2019-12-06 12:31:21
I have dynamic routes that could contain slashes or anti-slashes inside parameters , for example: http://localhost:4200/dashboard/T64/27D I should navigate to a page with route T64/27D Here's how I navigate this.router.navigate(['dashboard/'+this.groupListPage[0].code]); this.groupList[0].code contain T64/27D Actually Angular separate T64 and 27D as 2 different pages. Here's the error: ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'dashboard/T64/27D' Error: Cannot match any routes. URL Segment: 'dashboard/T64/27D' How can I tell to Angular that / is a part of

Get param from parent component to child component

纵饮孤独 提交于 2019-12-06 11:34:53
There have been so many alterations to the Angular router as of late I don't know how to go about this. I have a param on my parent component called "eventId" which is in the address bar: http://localhost:4200/event/1 In this case it's value is 1. Here's how I declare it in the routing component: { path: 'event/:eventId', loadChildren: './event/event.module#EventModule', canActivate: [AuthGuard] }, So I have a child component which is way down the line: http://localhost:4200/event/1/event-travel-agents/purchase-plans On my purchase plans component, how can I get the eventId? I've tried: import

Angular 4 animation for fade in and out a view

泪湿孤枕 提交于 2019-12-06 11:29:16
问题 I just want the view to fade in and out on route change. I have setup the component correctly it seems but need to get the animation syntax correct I think. This is my current animation attempt. I import this animation to my component: import {trigger, state, animate, style, transition} from '@angular/animations'; export function routerTransition() { return fadeInAndOut(); } function fadeInAndOut() { return trigger('routerTransition', [ transition(':enter', [ style({opacity: 0}), animate(3000

Adding new route to Jhipster using Angular 4

为君一笑 提交于 2019-12-06 09:30:52
I'm trying to add a new menu item to the default generated JHipster app. I'm using Angular 4 by the way. The problem I'm facing is that I'm always getting the error below. Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'user-profile' The following are the codes I added. Firstly, I added a folder named user-profile under src/main/webapp/app. In it, I added index.ts, user-profile.component.html, user-profile.component.ts and user-profile.route.ts The contents of index.ts export * from './user-profile.component'; export * from './user-profile.route'; The contents of

Unable to get the path nor url from angular router

泄露秘密 提交于 2019-12-06 07:27:36
I am unable to get the URL nor the path from ActivatedRoute nor Router imports. It outputs a blank for path "" and '/' for URL. I remember using a working version. The only thing that captures the right route the Router.events. I am also unable to subscribe to the URL in the ActivatedRoute. Here is the code import { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; import { Router, ActivatedRoute, UrlSegment, NavigationStart, RoutesRecognized } from '@angular/router'; @Component({ selector: 'api-dashboard', templateUrl: './dashboard.component.html', styleUrls: ['./dashboard

Angular 4 - Pass an object from one component to another (no parent - child hierarchy)

白昼怎懂夜的黑 提交于 2019-12-06 00:11:39
问题 My situation: I have a component showing tiles with each tile representing an object from an array that is looped over with an ngfor. When a tile is clicked I want to pass the object to a different component, which is responsable for displaying all properties of that object in fields that can be modified. What I have tried: After doing some research and coming across multiple posts showing me how to achieve this for a parent - child hierarchy and some posts explaining that it is necessary to

Hiding routes on url Angular 2+

情到浓时终转凉″ 提交于 2019-12-05 19:13:48
So I am trying to hide my routes on the url, that means i want my app to show always the url as being in the root app, for example: "www.foo.com" instead of "www.foo.com/login" Its there any way to achieve this in angular 2? Thanks in advance for the help! What you are looking for is Angulars skipLocationChange , this is what Angular refers to as "NavigationExtras". Here is the documentation: Angular docs on NavExtras // Navigate silently to /view this.router.navigate(['/view'], { skipLocationChange: true }); 来源: https://stackoverflow.com/questions/49407520/hiding-routes-on-url-angular-2