[英]Angular router.navigate doesn't route to resolver if on same component
[英]router.navigate(url) doesn't load the component but typing the url directly into the browser does
我正在嘗試通過單擊這樣的 div 來加載 Angular 8 組件:
showMovie(movieId) {
this.router.navigate([`/movie/${movieId}`]);
}
這曾經有效,並且在我在netlify
上部署的版本中它仍然有效,但是當我嘗試從localhost
執行此操作時,它不再有效。 如果我直接在瀏覽器中輸入 url,它就可以正常工作。
嘗試使用此代碼,使用 queryParams,我不確定語法:
this.router.navigate(['/movie'], {queryParams: {movieId: movieId }})
你可以試試這個:- 首先導入路由器
import { ActivatedRoute, Router } from '@angular/router';
在構造函數中聲明路由器:
private router: Router,
然后,
this.router.navigate(['/movie', movieId]);
感謝你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.