角度2:如何将相同的子组件与不同的数据一起使用? [英] Angular 2: How to use same child component with different data?
问题描述
我有一个包含菜单的标题,这些菜单包含相同的类别但不同的查询. 从父级到子级的第一次调用执行得很好,但是如果我从该子级组件内部导航到另一个类别,则会出错!
I have a header that has menu consist of categories which they are the same component but different query. The first call from parent to child is executed perfectly but if i navigateto another category from inside this child component i get error!
当我在这个孩子中导航时,我知道该链接有问题,这使[routerLink]立即更新. 另外,如果我从类别子组件导航到登录组件,而该组件是单独的组件,则会给我同样的错误!
I know this is something wrong with the link when i navigate inside this child which make [routerLink] updated instantly. Also if i navigate from category child component to login component which is separated component will give me the same error!
注意:在此链接中提出了同样的问题,没有答案
Note: Same question has been asked in this link with no answer
路由器配置
const APP_ROUTES: Routes = [
{path: 'landingpage', component: LandingpageComponent },
{path: '', component: IndexComponent, children: [
{path: '', component: HomeComponent},
{path: 'category/:cate', component: CategoryComponent },
{path: 'post/:id', component: PostComponent },
{path: 'profile/:id', component: ProfileComponent }
] },
{path: 'login', component: LogginComponent }
];
推荐答案
问题我经过深入搜索后解决了.我看到一个叫
Problem Solved by me after a deep search. i saw the response of a person called
brandonroberts :您的路由器链接无效,您需要设置一个终端 路线
brandonroberts: your router link is invalid and you either need to set a terminal route
这解决了我的问题...
and this solved my problem...
[routerLink]="['','category', cat.id]"
这篇关于角度2:如何将相同的子组件与不同的数据一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!