angular2-routing

Angular - Unhandled Navigation Error after building

前提是你 提交于 2021-02-18 22:08:47
问题 I have built a simple angular app with 2 routes through the following command: ng build --aot --prod --base-href ./ Then i open the index.html file located in the dist folder and the app runs but the the routes don't work and i get the following warning on console: Hope to have explained my question well. Thanks in advance. 回答1: Using Angular routing engine will force you to host your app in some server (e.g. IIS, NodeJS etc.) A simple angular app without routes can run without hosting it on

Angular 2 - Dynamic routing from JSON data

有些话、适合烂在心里 提交于 2021-02-18 07:56:29
问题 In Angular 2.0 stable, I have a application in which I have to define/config routes based on JSON data I receive. I don't have any predefined routes.I am getting this data in the constructor of my bootstrap component. How can i achieve that? Is it possible? 回答1: The way that I achieved this was to load the routes before bootstrapping the angular app. This way when the app starts all the dynamic routes are already there. So you have to load all the routes in the main.ts file before the

TS2416: Property 'canActivate' in type 'MyGuard' is not assignable to the same property in base type 'CanActivate'

橙三吉。 提交于 2021-02-08 13:57:58
问题 I have written an angular 4.3.0 typescript library. While building my library I saw below error in *.d.ts file. ERROR in [at-loader] ..\myLibrary\lib-commonjs\my-guard.service.d.ts:13:5 TS2416: Property 'canActivate' in type 'MyGuard' is not assignable to the same property in base type 'CanActivate'. Type '(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) => boolean | Promise | Observ...' is not assignable to type '(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) =>

CanLoad vs CanActivate for LazyLoading

依然范特西╮ 提交于 2021-02-07 11:57:19
问题 If I use lazy loading and have a guard defined for "CanLoad". Is "CanActivate" needed? As in is it possible for a module to be validly loaded but then the user does something which invalidates the "CanLoad" but since it is loaded the user can gets past the CanLoad. 回答1: CanActivate is not needed for lazy loading if you already implemented CanLoad. You may still want to replace the CanLoad with CanActivate if you need to check for unauthorized access. This is what the NG2 doc says The CanLoad

CanLoad vs CanActivate for LazyLoading

自作多情 提交于 2021-02-07 11:57:13
问题 If I use lazy loading and have a guard defined for "CanLoad". Is "CanActivate" needed? As in is it possible for a module to be validly loaded but then the user does something which invalidates the "CanLoad" but since it is loaded the user can gets past the CanLoad. 回答1: CanActivate is not needed for lazy loading if you already implemented CanLoad. You may still want to replace the CanLoad with CanActivate if you need to check for unauthorized access. This is what the NG2 doc says The CanLoad

Executing jQuery each in Angular 2 on route change

混江龙づ霸主 提交于 2021-02-07 10:37:18
问题 I am currently using Angular 2 with jQuery, the jQuery is concatenated into a separate file. This file exists out of many scopes, the scope is simply an on document ready function with an each on specific elements When reloading the browser on the correct page the code gets executed perfectly fine because it truly finds the elements on document ready, however when navigating from another page the code does not run. I tried working around the problem by setting an ngAfterViewInit() in the app

What all could be the reasons for a NavigationCancel event to get triggered?

半城伤御伤魂 提交于 2021-02-07 06:42:08
问题 I have a subscription for router events in angular2 , When I console the events, I find a NavigationCancel event with reason: "" . Curious to know what all could be the reasons for a NavigationCancel to get triggered. Not only with an empty reason but in general. 回答1: NavigationCancel will be triggered when you are trying to naviggate to a route and navigated route children can not be loaded (CanLoad guard) or route itself cannot be activated (CanActivate guard) you may use {enableTracing :

IE9 PathLocationStrategy Angular 4

烂漫一生 提交于 2021-02-04 15:32:16
问题 I'm using IE9 and PathLocationStrategy with Angular4 but it doesn't seem to be working. It just appends "#" infinite time. I tried adding history.js polyfill but nothing seems to be working. Can anyone help how do I use PathLocationStrategy with Angular 4 and IE9? Update: I finally figured concluded, we cannot use PathLocationStrategy on IE9. Now I'm trying to figure out how to use PathLocationStrategy on rest of the browser and only if IE9 is present, switch to HashLocationStrategy. I tried

How to test the existence of a route in Angular using Jasmine?

六眼飞鱼酱① 提交于 2021-01-29 11:27:58
问题 I'm trying to write a test that checks for the existence of a route using Jasmine for Angular application: import { routes } from './app-routing.module'; import { UsersComponent } from './users/users.component'; describe('routes', () => { it('should contain route for /users', () => { const expectedRoute = { path: 'users', component: UsersComponent }; expect(routes).toContain(expectedRoute); }); }); but the test fails (probably because of object equality in Javascript How object equality

Navigate to child route using named router outlet

那年仲夏 提交于 2021-01-29 07:34:40
问题 I have ngtabcontent so its content should be dynamic so create child routes for the PersonalComponent and Now on click of next it should navigate to its child route. const routes: { path: '', redirectTo: 'tenant', pathMatch: '{ path: "personal", component: children: [ { path: 'employer', component: AddemployerComponent, outlet: 'test'}, ] }, { path: "applicant", component: AddapplicantComponent }, { path: 'tenant', component: TenantappComponent }, { path: 'animal', component: