I have segmented my code into different folders such as
/posts
/events
/users
under each folder, there's a list component, a row component, and a detail component. the list will display the row component, when clicked, will load the detail component. using the segmented router feature of Angular 2, they all work, within their own folder/tree.
however, the row components of posts and events, will also load the user row component as well, in hope that when the user click on it, it will lead to the user detail page. but i can't work that out in the RouterConfig.
anybody knows how this should be accomplished? thanx
as requested, bellow is a sniplet
app component
@RouteConfig([
{ path: './posts/...', name: 'Posts', component: PostsComponent },
{ path: './users/...', name: 'Users', component: UsersComponent }
])
post component
@RouteConfig([
{ path: '/', name: 'PostList', component: PostListComponent },
{ path: '/:id', name: 'PostDetail', component: PostDetailComponent }
])
user component
@RouteConfig([
{ path: '/', name: 'UserList', component: UserListComponent },
{ path: '/:id', name: 'UserDetail', component: UserDetailComponent }
])
user list component
import {UserCardComponent} from './userCard.component';
@Component({
selector: 'my-page',
template: `
<card *ngFor="#user of userList" [user]="user"></card>
`,
directives: [
userCardComponent
],
providers: [
UserService
]
})
user card component
@Component({
selector: 'card',
template: `
<section (click)="onNavigate($event)">{{user.name}}</section>
`,
})
export class UserCardComponent {
@Input user;
constructor(
private _router: Router,
private _routeParams: RouteParams) {
}
onNavigate($event) {
this._router.navigate(['UserDetail', {id: this.user.id.toString() }]);
}
}
post detail component
import {UserCardComponent} from '../users/userCard.component';
@Component({
selector: 'page',
template: `
<card [user]="post.user"></card>
`,
directives: [
UserCardComponent
]
export class PostDetailComponent {
};
So everything shows up okay, but, when PostDetailComponent is displayed, click on the UserCardComponent, I get an error
Component "PostDetailComponent" has no route config.
So, the question is, how do I configure the router so I can go directly from /posts/:id to /users/:id