angular2-routing

Angular 2 - test for change in route params

被刻印的时光 ゝ 提交于 2019-12-03 11:33:59
问题 I have a component in angular 2 which responds to changes in the route parameters (the component doesn't reload from scratch because we're not moving out of the main route. Here's the component code: export class MyComponent{ ngOnInit() { this._routeInfo.params.forEach((params: Params) => { if (params['area']){ this._pageToShow =params['area']; } }); } } This works a treat and _pageToShow is set appropriate on navigation. I'm trying to test the behaviour on a change to the route (so a second

RC.5 throws \"Cannot find 'default' when lazy loading module with routes

雨燕双飞 提交于 2019-12-03 11:14:04
tried to lazy load a module in an angular2 rc. app. This module contains routes itself. The app is trying to lazy load the module on clicking the route it is registered on but immediately throws Error: Uncaught (in promise): Error: Cannot find 'default' in './app/test/test.module' Routes in app are defined like: export const routes: Routes = [ { path: '', component: StartComponent }, { path: 'route1', component: Route1Component }, { path: 'test', loadChildren: './app/test/test.module'}, { path: '**', component: StartComponent } //page not found ]; The TestModule contains following routes:

Angular2 Routing: persisting route tabs and child routes

非 Y 不嫁゛ 提交于 2019-12-03 11:04:42
问题 Angular Community! I'm currently rewriting AngularJS app to Angular 2. I want to solve problem which could be described as: route tabs + child routes. So, basically Router in Angular 2 destroys inactive components (my tabs!). The problem is I don't want this behaviour. Reason is I have some components like charts and data grid and want to switch between them fast, I don't want to recreate them. I have found some workaround to persist my tabs while having routes but using this approach I don't

How to make a named routing outlet work with loadChildren?

試著忘記壹切 提交于 2019-12-03 10:50:16
问题 I've created two plunkers concerning an issue with routing's loadChildren and outlet navigation. For some reason, having an empty base path within the loaded child module does not work with outlet navigation. In this example, pressing the 'Contact' link fails. app-routing.module const appRoutes: Routes = [ { path: 'admin', loadChildren: () => AdminModule }, { path: '', redirectTo: '/admin', pathMatch: 'full' } ]; admin-routing.module const adminRoutes: Routes = [ { path: '', component:

Cannot read property 'outlets' of null

与世无争的帅哥 提交于 2019-12-03 10:26:22
I have next problem : Cannot read property 'outlets' of null . My project works, but after some time it stopped working, but i didn't change my code. Help me please. Update My component with router-outlet: import { Component } from '@angular/core'; @Component({ selector: 'app', template: ' <nav-menu></nav-menu> <router-outlet></router-outlet> <footer-component></footer-component> ', }) export class AppComponent {} app.module: import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { RouterModule } from '@angular/router'; import {

Angular2: unable to navigate to url using location.go(url)

我只是一个虾纸丫 提交于 2019-12-03 10:07:05
I am trying to navigate to a specific url using location.go service from typescript function. It changes the url in the browser but the component of the url is not reflected in the screen. It stays on the login (actual) screen - say for eg: constructor(location: Location, public _userdetails: userdetails){ this.location = location; } login(){ if (this.username && this.password){ this._userdetails.username = this.username; this.location.go('/home'); } else{ console.log('Cannot be blank'); } } Is there a compile method or a refresh method I am missing? Yes, for redirecting from one route to

Angular 2: NavigationCancel - Navigation ID 2 is not equal to the current navigation id 3

一个人想着一个人 提交于 2019-12-03 09:48:16
I'm trying to redirect old URLs (links in email templates) from a previous site to another route like this: if (route.url.indexOf('/#/') !== -1) { this.router.navigate(['/my-route']); } However, the navigation gets cancelled with the following reason: Navigation ID 2 is not equal to the current navigation id 3 . Looking at the Angular 2 router source, this happens in the runNavigate method when id !== this.navigationId ( https://github.com/angular/angular/blob/master/modules/@angular/router/src/router.ts#L652 ). I can't find any information about the navigationId property, why this happens and

Angular 2 resolver with loading indicator

筅森魡賤 提交于 2019-12-03 09:27:12
问题 I use resolvers to load the data into the components, but until the data is not returned from the server the component does not load. I would like to know if there is a way to render a load indicator before the server responds. 回答1: You can use the "reacting to routing events" strategy that consist to implement the App to react when any routing event occurs. To do that, you will need in your app.component.ts some code like: import { Component } from '@angular/core'; import { Router,

How to separate admin and the front web in angular 2 project

人走茶凉 提交于 2019-12-03 09:02:05
I'm going to build a full project using angular 2, the project contains admin panel and a front-end web for users. I don't know how to separate admin from the web, should I use routing for this? But this will require me to import all components inside the app.module.ts or there is another way to use two app.module.ts one for the web and one for the admin? Or what should I do? I've built this recently and what I did was simply to split the routes into two different modules. So you'd have this: - +admin - routes - +dashboard - +login - ... etc - +website - routes - +home - +profile - ... etc

Angular: append query parameters to URL

瘦欲@ 提交于 2019-12-03 07:11:57
问题 Im using this: import { HttpParams } from '@angular/common/http'; let params = new HttpParams(); params.append('newOrdNum','123'); But this is not working, i dont append param in url. Any suggestion? 回答1: This could be archived by using the Router class: Using a component: import { Router, ActivatedRoute } from '@angular/router'; @Component({}) export class FooComponent { constructor( private _route: ActivatedRoute, private _router: Router ){} navigateToFoo(){ // changes the route without