Angular 2 Routing:如何更改Id

时间:2018-03-30 09:35:24

标签: angular typescript routing

我正在使用路由构建角度2。

app.routing.module.ts

URL url = ExternalLibray.class.getResource("resources/myhtml.html");
WebArchiveReader wr = new WebArchiveReader();
// or can be simply, ExternalLibray.class.getResourceAsStream...
if( wr.readWebArchive( url.openStream() ) ) {
    wr.loadToWebView(webview);
}

当我点击我通过传递ID获取数据来获取数据时,网址看起来像http://localhost:4200/Ddata/1

我想将此网址修改为http://localhost:4200/Ddata/name

请帮帮我

1 个答案:

答案 0 :(得分:1)

您想要路由掩蔽,但实现此目的的唯一方法是让后端接受名称而不是id。

如果你不能改变你的后端,你也可以使用矩阵参数。网址如下所示:http://localhost:4200/Ddata/name;id=1。这对用户来说会更清洁,你仍然可以从激活的路线的参数中读取id。

official documentation

中阅读有关矩阵参数的更多信息