[英]router.navigate(url) doesn't load the component but typing the url directly into the browser does
I'm trying to load an Angular 8 component by clicking on a div like this:我正在尝试通过单击这样的 div 来加载 Angular 8 组件:
showMovie(movieId) {
this.router.navigate([`/movie/${movieId}`]);
}
This used to work, and in my deployed version on netlify
it still works, but when I try to do it from localhost
it doesn't anymore.这曾经有效,并且在我在
netlify
上部署的版本中它仍然有效,但是当我尝试从localhost
执行此操作时,它不再有效。 If I type the url directly in the browser tho, it works just fine.如果我直接在浏览器中输入 url,它就可以正常工作。
尝试使用此代码,使用 queryParams,我不确定语法:
this.router.navigate(['/movie'], {queryParams: {movieId: movieId }})
You can try this:- At first import router你可以试试这个:- 首先导入路由器
import { ActivatedRoute, Router } from '@angular/router';
declare router in constructor:在构造函数中声明路由器:
private router: Router,
then,然后,
this.router.navigate(['/movie', movieId]);
thank u感谢你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.