簡體   English   中英

router.navigate(url) 不加載組件,但直接在瀏覽器中輸入 url

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM