Angular 4使用相同组件的几个routerLinks

时间:2017-07-01 02:43:54

标签: angular angular-ui-router routerlink

我在尝试找到解决方法时遇到了一些麻烦:

一方面,我已经定义了以下路线:

const appRoutes: Routes = [
    { path: '**', component: TemplateComponent, pathMatch: 'full' }
];

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes); 

因此,基于URL,TemplateComponent将获取不同的html模板:

@Component({
    templateUrl: this.document.location.pathname
})

另一方面,我的后端服务器生成一些HTML输出,如下所示:

<nav>
    <a routerlink="/content/mysite/t1.html" href="/content/mysite/t1.html">Template 1</a>
    <a routerlink="/content/mysite/t2.html" href="/content/mysite/t2.html">Template 2</a>
    <a routerlink="/content/mysite/t3.html" href="/content/mysite/t3.html">Template 3</a>
</nav>

所以我面临的问题是,当点击任何生成的链接时,Angular不会提取模板,也不会初始化组件,这只在加载AppModule时执行一次。

我发现一些文章讨论了必须实现订阅者,虽然在浏览了Angular 4文档并且尝试了不同的事情后,我最终失败了。

如果有人能说清楚,那就太好了。

0 个答案:

没有答案
相关问题