Angular:Router.navige不在某些页面上加载组件
我将Angular从10更新到12,在迁移后,我的网站的某些页面不再使用Router.navigate.navigate
(或routerlink
)加载组件。尽管URL更改并正确(如果我刷新,则加载了正确的内容)。据我了解,这可能来自路由表
,但是我并没有真正看到这将如何解释它,因为它在Angular 10中起作用。
Shell.childRoutes([
{
path: '',
component: LoginComponent,
canActivate: [RedirectionGuardService],
pathMatch: 'full'
},
{
path: 'component1',
component: componentComponent1,
data: { title: marker('Component1'), data: { roles: ['Role.USER'] } },
},
{
path: 'component2/:query',
component: component2Component,
data: { title: marker('component2') },
resolve: { data: component2Resolver },
},
{
path: 'component3/:id/:value',
component: component3Component,
resolve: { data: component3Resolver },
data: { title: marker('component3') },
},
{
path: 'component4/:id',
component: component4Component,
resolve: { data: component4Resolver },
data: { title: marker('component4') },
},
{
path: 'component5/:id',
component: component5Component,
resolve: { data: component3Resolver },
data: { title: marker('component5') },
},
]),
{
path: 'waitingComponent',
component: waitingComponent,
data: { title: marker('Waiting') },
},
{
path: 'uploadModal/:id/:value',
component: UploadModalComponent,
data: { title: marker('Upload Content') },
},
{
path: 'faq',
component: FAQComponent,
},
在我提供的代码中,router.navigate
在component2
或uploadcomponent
中不起作用,但在component1
或component3
。
是关于如何编写router.navigate
的问题:
this.router.navigate(['/component3/',this.value1, this.value2]);
如果这
我还尝试使用固定值尝试,但不会改变情况。 URL会更改,但没有变化。
在编译或使用浏览器(控制台或网络)的过程中,我不会收到任何错误。
任何帮助都是有价值的。
I updated Angular from 10 to 12, and after the migration some pages of my website no longer load the components with a router.navigate
(or a routerLink
for that matter), although the URL is changed and correct (if I refresh, the right content is loaded). From what I understand this could come from the routing-table
, but I don't really see how that would explain it since it worked back in angular 10.
Shell.childRoutes([
{
path: '',
component: LoginComponent,
canActivate: [RedirectionGuardService],
pathMatch: 'full'
},
{
path: 'component1',
component: componentComponent1,
data: { title: marker('Component1'), data: { roles: ['Role.USER'] } },
},
{
path: 'component2/:query',
component: component2Component,
data: { title: marker('component2') },
resolve: { data: component2Resolver },
},
{
path: 'component3/:id/:value',
component: component3Component,
resolve: { data: component3Resolver },
data: { title: marker('component3') },
},
{
path: 'component4/:id',
component: component4Component,
resolve: { data: component4Resolver },
data: { title: marker('component4') },
},
{
path: 'component5/:id',
component: component5Component,
resolve: { data: component3Resolver },
data: { title: marker('component5') },
},
]),
{
path: 'waitingComponent',
component: waitingComponent,
data: { title: marker('Waiting') },
},
{
path: 'uploadModal/:id/:value',
component: UploadModalComponent,
data: { title: marker('Upload Content') },
},
{
path: 'faq',
component: FAQComponent,
},
In the code I provided, router.navigate
doesn't work in component2
or uploadComponent
but works in component1
or component3
.
If it's a matter of how the router.navigate
is written:
this.router.navigate(['/component3/',this.value1, this.value2]);
(This is used by the UploadComponent
as an example).
I also tried it with a fixed value to try, and it doesn't change the situation. The URL changes, but not the component.
I don't receive any errors during compiling or with the browser (console or network).
Any help would be of value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我找到了引起问题的原因,花了我一段时间,但是这里是。
在
Routereusestrategy
的配置中,参数shore reuseroute
是错误配置的,在Angular 10和11之间的更改中,发生了变化,并且以前的配置不再符合Angular的标准。配置应该看起来像这样:
返回Future.RouteConfig === Current.RouteConfig;
希望这将帮助那些在从Angular 10迁移到Angular 11期间也遇到此问题的人。
Okay I found what was causing the problem, took me a while but here it is.
In the configuration of
RouteReuseStrategy
the parametershouldReuseRoute
was wrongly configured, during the change between Angular 10 and 11 something changed and the former configuration was no longer up to the standards of Angular.The configuration should look something like this :
return future.routeConfig === current.routeConfig;
Hopefully this will help people who also had this problem during a migration from Angular 10 to Angular 11.