angular2-routing

Angular 2 add routerLink in child which points to root router

被刻印的时光 ゝ 提交于 2019-11-28 07:31:50
问题 Currently I am developing a web app using Angular 2 Beta 8. Now I am facing a problem with nested routes when using the routerLink directive. The router hierarchy is: AppCmp |-> NewItemFormCmp |-> UserDashboardCmp |-> MyItemsCmp The involved components are: @Component({ ... }) @RouteConfig([ {component: NewItemFormCmp, name: 'NewItemForm', path: '/item/new'}, {component: UserDashboardCmp, name: 'UserDashboardCmp', path: '/me/...', useAsDefault: true} ]) export class AppCmp { } @Component({ ..

Use RouterLink from a nested component

蹲街弑〆低调 提交于 2019-11-28 07:31:24
问题 Using Angular 2 beta.0 I have a component structure like so App (Has RouteConfig) -> List | -> ListItem (Want to use RouterLink from here) This results in an error: Component "List" has no route config. So I put a RouteConfig on the List component like so... @RouteConfig([ {path: '/:id', name: 'Details', component: Detail} ]) But I get an error in angular like Error: Child routes are not allowed for "/list". Use "..." on the parent's route path. I have tried adding these 3 dots before and

How to get current route custom data in angular 2?

流过昼夜 提交于 2019-11-28 06:51:42
I have set up routes is like below const appRoutes: Routes = [ { path: 'login', component: LoginComponent, data: { title: 'Login TTX' } }, { path: 'list', component: ListingComponent, data: { title: ' TTX Home Page', module:'list' } }, { path: '', redirectTo: '/login', pathMatch: 'full' }, ]; now when i come to '/list' route then on 'listing.component.ts' i have written below code export class ListingComponent { public constructor(private router:Router) { //here how i can get **data** of **list** routes } } public constructor(private route:ActivatedRoute, private router:Router) { console.log

Angular2 router: how to correctly load children modules with their own routing rules

孤街浪徒 提交于 2019-11-28 06:46:26
here is my Angular2 app structure: Here is part of my code. The following is the main module of the Angular2 app, that imports its routing rules and a child module ( EdgeModule ) and uses some components related to some pages. app.module.ts @NgModule({ declarations: [ AppComponent, PageNotFoundComponent, LoginComponent ], imports: [ ... appRouting, EdgeModule ], providers: [ appRoutingProviders, LoginService ], bootstrap: [AppComponent] }) export class AppModule { } Here is the routing rules for the main module. It have paths to login page and page not found. app.routing.ts const appRoutes:

ASP.NET 5 + Angular 2 routing (template page not REloading)

风流意气都作罢 提交于 2019-11-28 06:23:34
Angular 2 beta uses html5 routing by default. However, when you go to a component and the route changes (eg http://localhost:5000/aboutus ) and you reload/refresh the page, nothing is loaded. The issue has been raised in this post also. Most of the answers say that if we are going to pursue HTML5 routing in angular 2, then this issue of routing should be taken care of in server-side. More discussion here . I am not sure how to handle this issue using the asp.net server environment. Any angular 2 devs out there who also uses asp.net and encounters this issue? PS. I'm using ASP.NET 5. My Angular

Angular 2 router.navigate

不问归期 提交于 2019-11-28 05:41:17
I'm trying to navigate to a route in Angular 2 with a mix of route and query parameters. Here is an example route where the route is the last part of the path: { path: ':foo/:bar/:baz/page', component: AComponent } Attempting to link using the array like so: this.router.navigate(['foo-content', 'bar-contents', 'baz-content', 'page'], this.params.queryParams) I'm not getting any errors and from what I can understand this should work. The Angular 2 docs (at the moment) have the following as an example: { path: 'hero/:id', component: HeroDetailComponent } ['/hero', hero.id] // { 15 } Can anyone

Pass parameter into route guard

二次信任 提交于 2019-11-28 05:36:59
I'm working on an app that has a lot of roles that I need to use guards to block nav to parts of the app based on those roles. I realize I can create individual guard classes for each role, but would rather have one class that I could somehow pass a parameter into. In other words I would like to be able to do something similar to this: { path: 'super-user-stuff', component: SuperUserStuffComponent, canActivate: [RoleGuard.forRole('superUser')] } But since all you pass is the type name of your guard, can't think of a way to do that. Should I just bit the bullet and write the individual guard

Modify data object in ActivatedRoute

僤鯓⒐⒋嵵緔 提交于 2019-11-28 05:24:58
问题 I need to modify the breadcrumb value in the data object of my current route. Here is my route configuration. { path: "users", component: UserListComponent, children: [ { path: ":id", component: UserComponent, data: { breadcrumb: '<User name here>' }, } ], data: { breadcrumb: 'Users' } }, I am trying to do this: this._route.data = { breadcrumb: this.user.displayName }; //_route is ActivatedRoute but it doesn't work. Any help would be appreciated. Thanks. 回答1: The data property of a route is

Angular 2 - replace history instead of pushing

我的未来我决定 提交于 2019-11-28 05:18:43
How to replace a history instead a pushing a new in angular 2's new router (rc.1)? For example Im in a question list ( /questions ) opening a new modal in a new route ( /questions/add ), and after adding a new question I go to the question view ( /questions/1 ). If I press back I would like to go to the /questions instead of /questions/add If you use router.navigate And then location.replaceState With the exact same path, you can trigger changes that usually happen, as well as replacing the history. For example, in your case: this.router.navigate(['questions/1']); this.location.replaceState(

Angular 2 route change to same component causing reload

社会主义新天地 提交于 2019-11-28 05:12:06
问题 Looking for some advice on why a route change to the same component in my Angular 2 application is reloading the component. I have 2 routes, both with the same component: /home /home/:id const appRoutes = [ {path:'', redirectTo:'/home', pathMatch:'full'}, {path:'home', component: HomeComponent}, {path:'home/:id', component: HomeComponent}, ]; When changing between the two routes, the component is reloaded. When changing the parameter on the second route, the component is not reloaded (as