简体   繁体   English

router.navigate(url) 不加载组件,但直接在浏览器中输入 url

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

相关问题 如果在同一组件上,Angular router.navigate 不会路由到解析器 - Angular router.navigate doesn't route to resolver if on same component 骨干路由器.navigate不重定向 - Backbone router.navigate doesn't redirect router.navigate(url) 未通过 Service Worker 获取事件 - router.navigate(url) not going through Service worker fetch event React Router 在地址栏中加载 URL 但不加载组件 - React Router loads URL in address bar but doesn't load component 反应路由器:链接更改URL,但不加载组件 - React router: Link changes url but doesn't load component 在浏览器(react-router-dom)中直接输入 url 时如何修复 404 错误? - How to fix an 404 error when directly typing in the url in the browser (react-router-dom)? Angular 4,路由器4.0.0:routerLink或router.navigate不会以编程方式重定向到子路由 - Angular 4, Router 4.0.0: routerLink or router.navigate programatically doesn't redirect to child routes 反应路由器 dom 中的链接仅不加载页面 url 浏览器导航已更改 - Link in react router dom doesn't load page only url browser nav gets changed 到达路由器导航更新 URL 但不是组件 - Reach router navigate updates URL but not component Angular 2 router.navigate - Angular 2 router.navigate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM