angular2-routing

Angular 2 Lazy loading a NgModule in a NPM module with angular router

左心房为你撑大大i 提交于 2019-12-04 04:49:27
I have been lazy loading modules in routes e.g. export const HomeRoute: Route = { path: '', component: HomeComponent, canActivate: [AuthGuard], children: [ {path: 'dashboard', loadChildren: 'app/+dashboard/db.module#DashboardModule'} ] }; I would like to put my "pages" into NPM modules. What is the route to the node_module that I should use in the loadChildren attribute? I am using angular-cli 1.0.0-beta.16 I have tried {path: 'lazy', loadChildren: '../node_modules/hello-world/components#HelloWorld' } also {path: 'lazy', loadChildren: 'hello-world/components#HelloWorld' } The exported class is

How to render a grandchild view into the same router-outlet as the first child?

情到浓时终转凉″ 提交于 2019-12-04 04:20:22
问题 This is a follow up question to this: Angular 2 how does auxiliary routes work in 2.1.0? I also tried looking at this but it doesn't really shed any light on the issue: How to render the child route into the router-outlet of the parent`s parent If I have a parent route /admin which has a <router-outlet name="admin"></router-outlet> which looks like this: const routes: Routes = [ { path: '', component: AdminAreaComponent, canActivate: [AuthGuardService] }, { path: 'login', loadChildren: '..

Calling Angular2SocialLoginModule function calls not supported

孤人 提交于 2019-12-04 04:10:19
问题 I am new to angular js2. Currently I am working with a web application, which uses angular2 for front-end. In this application I have used angular2-social-login for authentication purpose. But when I run the npm start I got the below error ERROR in Error encountered resolving symbol values statically. Calling function 'Angular2SocialLoginModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in

Angular 2.0, how to detect route change on child component

瘦欲@ 提交于 2019-12-04 03:46:54
How can I detect a route change on a child component?. This is what I have tried, but I only see the app component trace the route change. I want to be able to detect when the url change from e.g. #/meta/a/b/c to #/meta/a/b/c/d in the MetaDetailView component. @RouteConfig([ { path: '/', name: 'Home', redirectTo: ['Meta']}, { path: '/meta/...', name: 'Meta', component: MetaMainComponent, useAsDefault: true}, ...other routes..., ]) export class AppComponent { constructor(private _router: Router) { _router.subscribe( (url) => console.log("app.url = " + url)); } } @RouteConfig([ { path: '/*other'

Can RouteData in Angular 2 pass variables to routed components from parent component?

[亡魂溺海] 提交于 2019-12-04 03:46:20
问题 I would like to use the RouteConfig to pass a variable from my AppComponent to Coursescomponent, but the "data" property in route config can only pass constant parameter, and it cannot recognize "this". Is there a way to do this? If not, what is a best practice to pass variables to routed components? @Component({ selector: 'app', template: ` <router-outlet></router-outlet> `, directives: [ROUTER_DIRECTIVES], }) @RouteConfig([ { path: '/courses' , name: 'Courses' ,component: CoursesComponent

Good template strategy for authentication in Angular 2

雨燕双飞 提交于 2019-12-04 03:39:09
I currently have an Angular 2 app up and running that looks as follows: App.component is bootstrapped when visiting the site. The template for App.component has all component tags (for example menu.component, search.component and the router-outlet). What I basically need is the following: currently a visitor is directly redirected to the Login page because the user needs to login. He is still able to see the menu and all components that are only there for logged in users. What would be the best strategy to add an extra template layer, so not logged in users get redirected? The way that I've

Angular 2 Router, href links and unwanted page refresh

↘锁芯ラ 提交于 2019-12-04 03:09:20
问题 i am currently experimenting with angular2 (beta1) and i'm a bit puzzled about the new router. Navigating via router.navigate works like a charm, while trying to do that via a normal link to a registered route refreshes the page. This happens with PathLocationStrategy of course, as HashLocationStrategy works as expected. Is this a bug or the normal behaviour? TIA 回答1: You should use a routerLink instead. For example <a [routerLink]="[ '/MyCmp', {myParam: 'value' } ]"> See also https://angular

Router named outlets that are activated once

∥☆過路亽.° 提交于 2019-12-04 03:01:35
问题 Is it possible to have router named outlets that are activated once and then never destroyed, no matter what route is navigated in primary outlet? The intention is to have components that persist on page (for instance, sidebar ) but get the benefits of routing on their initial load - such as guards (resolvers) and lazy loading. The requirement is that named outlets shouldn't affect UX in any negative way, for example by introducing garbage suffixes to SPA URL, e.g. (outletName:routeName) ,

Passing dynamic data through Angular 2 route

家住魔仙堡 提交于 2019-12-04 02:37:12
It is possible to pass static data to an Angular 2 route without showing it on the URL. But how can I pass dynamic data/object in the same way? Günter Zöchbauer You can use a resolver. The data returned by a resolver is made available to routes the same way static data on route configurations is For an example see https://angular.io/guide/router#resolve-guard @Injectable() export class CrisisDetailResolve implements Resolve<Crisis> { constructor(private cs: CrisisService, private router: Router) {} resolve(route: ActivatedRouteSnapshot): Promise<Crisis>|boolean { let id = route.params['id'];

Angular Router example Best way to upgrade to include .angular-cli.json and bypass Cannot read property 'config' of null

时光毁灭记忆、已成空白 提交于 2019-12-04 02:29:56
问题 I tried downloading the Routing and Navigation example from this page Here's the link to the specific zip. I run the following sequence of commands: npm install npm install --save-dev @angular/cli@latest ng -v ng serve -o From what I can make out Cannot read property 'config' of null is somehow related to a bad version of the CLI. But if I create a new project I can start it successfully with my existing setup ng new router cd router npm install ng serve -o Old directory structure (from zip