我想从解析器获取博客标题后,将我的网址/blog/:id
更改为/blog/blog-title
。示例:当我导航到blog/1
并且ID为1的博客标题为how-can-i-make-this
时,网址应为/blog/how-can-i-make-this
。我怎么能在角4中做到这一点?
答案 0 :(得分:0)
使用Angular的路由器并使用其导航功能:
<强>打字稿强>
import {Router} from '@angular/router'; // import the router
constructor(private router:Router){} //put this in your contructor
// call this when you want to change you want to change the url
somefunction() {
this.router.navigate(['how-can-i-make-this']).then(response => {
console.log(response);
});
}
如果您不想重新加载,请参阅以下答案: Change route params without reloading in angular 2
答案 1 :(得分:0)