Ala*_*412 5 angular-ui-router angular
我想用破折号分隔 URL 中的参数,如下所示:
localhost/add/5-ninja
Run Code Online (Sandbox Code Playgroud)
这里的 id 是 5,名字是 ninja。当我将配置更改为:
path: '/:id-:name'
它无法正常工作。如何在 URL 中创建破折号分隔的参数
我认为按照您喜欢的方式不可能,但这是我实现该结果的建议:
/:dashed在你的组件中:
import { ActivatedRoute } from '@angular/router';
class MyComponent {
constructor(private _route: ActivatedRoute) {
const [id, name] = _route.snapshot.params.dashed.split('-');
// you've got two variables 'id' and 'name' thanks to the array destructing
}
}
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
2497 次 |
| 最近记录: |