angular2-routing

Routing and navigation in Angular 2

家住魔仙堡 提交于 2019-11-28 01:02:47
I am going through the tutorials for Angular 2 and have been able to get a simple application up and running. Now, I am moving on to the routing and navigation part found here https://angular.io/docs/ts/latest/guide/router.html , but something isn't working for me. I went to the live example in Plunker and downloaded the code from there. I then setup a solution in Visual Studio 2015 and plugged in all of the code from the Plunker download. The application works perfectly except for one thing, the navigation doesn't seem to work as the documentation would seem to indicate. I start debugging the

Angular2 Routing: import submodule with routing + making it prefixed

心不动则不痛 提交于 2019-11-28 00:54:17
问题 I have a main module and some submodules. And I want to specify some not trivial routing between them. I'd prefer defining the routes of a submodule within the submodule. E.g.: @NgModule({ imports: [ /*...*/ RouterModule.forChild([ { path: 'country', redirectTo: 'country/list' }, { path: 'country/list', component: CountryListComponent }, { path: 'country/create', component: CountryCreateComponent }, /*...*/ ]) ], declarations: [/*...*/], exports: [ RouterModule, ], }) export class

Passing objects in routing [duplicate]

感情迁移 提交于 2019-11-28 00:29:58
问题 This question already has answers here : How do I pass data to Angular routed components? (12 answers) Closed last year . I have a component in Angular2 hosting the table of users (userTableComponnent) and another component of userDetails. Upon clicking on a row in users table, I want to route to the userDetails. One implementation is to pass the userId only, so in userDetails, I fetch the details of the user with another http get. However, this is redundant, as I grab all the user info in

How to handle angular2 route path in Nodejs?

最后都变了- 提交于 2019-11-27 22:52:15
I am working on a NodeJS app with Angular2. In my app, I have a home page and search page. For home page I have an HTML page that will render for the localhost:3000/ and from home page user navigate to search i.e localhost:3000/search page that I handled by angular2 routes . I don't have the page for the search page its view render by the angular2. But when I directly hit localhost:3000/search as I don't have this routing in my node app it gives the error. I don't know How to handle this in node app? If you enter localhost:3000/search directly in the browser navigation bar, your browser issues

Angular2: Global Guard (user has to be logged in always)

孤街醉人 提交于 2019-11-27 22:25:52
I'm building an application where there's no access at all for unauthenticated users. I wrote a LoggedInGuard , but now I have to add canActivate: [LoggedInGuard] to every route inside my router configuration (except the LoginComponent ). Is there a better way to get this working? My file / module layout looks like this: app/ AppModule AppRoutingModule AppComponent authentication/ AuthenticationModule AuthenticationRoutingModule LoginComponent contacts/ ContactsModule ContactsRoutingModule ContactListComponent users/ UsersModule UsersRoutingModule UserEditComponent ... Maybe it's possible to

Angular2 AOT with Lazy loading Can't resolve [path to lazy module].ngfactory.ts

北城以北 提交于 2019-11-27 22:21:32
问题 I am trying to convert an App that was already working with Lazy loaded modules into AOT. I am using the @ngtools/webpack toolkit to compile the AOT code, however I am getting into an error that Angular cant find the Lazy loaded module's code as it seems. ERROR in ./src/ngfactory async Module not found: Error: Can't resolve '/Library/WebServer/Documents/envato-teams/src/ngfactory/src/app/components/container/projects.ngfactory.ts' in '/Library/WebServer/Documents/envato-teams/src/ngfactory' @

Passive Link in Angular 2 - <a href=“”> equivalent

感情迁移 提交于 2019-11-27 20:09:04
问题 In Angular 1.x I can do the following to create a link which does basically nothing: <a href="">My Link</a> But the same tag navigates to the app base in Angular 2. What is the equivalent of that in Angular 2? Edit: It looks like a bug in the Angular 2 Router and now there is an open issue on github about that. I am looking for an out of the box solution or a confirmation that there won't be any. 回答1: If you have Angular 5 or above, just change <a href="" (click)="passTheSalt()">Click me</a>

Angular2 Router - Anyone know how to use canActivate in app.ts so that I can redirect to home page if not logged in

╄→гoц情女王★ 提交于 2019-11-27 19:52:30
Angular2 Router - Anyone know how to use canActivate in app.ts so that I can redirect to home page if not logged in I'm using typescript and angular 2. Current attempt under my constructor in my app.ts file: canActivate(instruction) { console.log("here - canActivate"); console.log(instruction); this.router.navigate(['Home']); } It currently doesnt get hit. Any idea why? inoabrian So the documentation looks like this is what it exports. export CanActivate(options : CanActivateAnnotation) : (hook: (next: ComponentInstruction, prev: ComponentInstruction) => Promise<boolean>| boolean) =>

Angular 2 Final Release Router Unit Test

匆匆过客 提交于 2019-11-27 19:41:53
How do I unit test routers in Angular version 2.0.0 with karma and jasmine? Here's what my old unit test looks like in version 2.0.0-beta.14 import { it, inject, injectAsync, beforeEach, beforeEachProviders, TestComponentBuilder } from 'angular2/testing'; import { RootRouter } from 'angular2/src/router/router'; import { Location, RouteParams, Router, RouteRegistry, ROUTER_PRIMARY_COMPONENT } from 'angular2/router'; import { SpyLocation } from 'angular2/src/mock/location_mock'; import { provide } from 'angular2/core'; import { App } from './app'; describe('Router', () => { let location, router;

Service is not being singleton for angular2 router lazy loading with loadChildren

断了今生、忘了曾经 提交于 2019-11-27 18:49:06
Here is the pluker. https://plnkr.co/edit/tsNlmRth4mRzz0svGWLK?p=preview In which I have created two module with two components and one service each. I want the service should be singleton (save state) in the module level. If you click on 'Module 1 Page 1' and 'Module 2 Page 2' It will display two different random numbers. As I am generating this number in constructor. So the service is being created each time page change. But module2 is behaving perfectly. Note: Mode1Module is using loadChildren Mode2Module is using children I found this same type issue is been fixed earlier as per this