在Angular的routerLink中,一般应该使用问号作为参数分隔符。但是当参数值中包含问号时,会导致URL解析错误,因此可以使用分号代替问号。
示例代码如下:
@Component({ selector: 'example', templateUrl: './example.component.html' }) export class ExampleComponent implements OnInit { id: string; name: string;
constructor(private route: ActivatedRoute) { }
ngOnInit() { this.route.params.subscribe(params => { this.id = params['id']; this.name = params['name']; }); } }
通过这种方法,我们就可以正确地获取到URL中的参数值并进行处理。