angular : 定义带有扩展名的路由
angular : Define route with extension
如何在模式中定义带有 .html 的 angular 4 路由?
示例:假设 url 是 mydomain.com/collections/test.html。当我在组件中获取路由参数时,我想检索 'test' 作为值,而不是 'test.html'
定义路由的文件
const routes: Routes = [
{path: 'collections/:tag.html', component: CollectionDetailsComponent},
];
在CollectionDetailsComponent.ts
ngOnInit()
{
this.route.params.forEach((params: Params) =>
{
let tag = params['tag'];
//Here tag contains ".html" at the end
谢谢
我只看到两种方式
添加虚拟子路由(使用您选择的课程名称)
{path: 'collections/:tag/dummy.html', component: CollectionDetailsComponent},
将 .html
添加到值
{path: 'collections/:tag', component: CollectionDetailsComponent},
并使用 foo.html
作为标签值。
如果 URL 中的 .
会导致任何问题,我还没有尝试过,但我想记住很久以前就有相关的错误报告已修复。
如何在模式中定义带有 .html 的 angular 4 路由?
示例:假设 url 是 mydomain.com/collections/test.html。当我在组件中获取路由参数时,我想检索 'test' 作为值,而不是 'test.html'
定义路由的文件
const routes: Routes = [
{path: 'collections/:tag.html', component: CollectionDetailsComponent},
];
在CollectionDetailsComponent.ts
ngOnInit()
{
this.route.params.forEach((params: Params) =>
{
let tag = params['tag'];
//Here tag contains ".html" at the end
谢谢
我只看到两种方式
添加虚拟子路由(使用您选择的课程名称)
{path: 'collections/:tag/dummy.html', component: CollectionDetailsComponent},
将 .html
添加到值
{path: 'collections/:tag', component: CollectionDetailsComponent},
并使用 foo.html
作为标签值。
如果 URL 中的 .
会导致任何问题,我还没有尝试过,但我想记住很久以前就有相关的错误报告已修复。