1

@ngxs/storage-plugin@ngxs/router-plugin导致路由中断一起使用。如果我删除其中任何一个路由工作正常。对于它们,如果我在浏览器中键入 URL,它总是返回到最后一个路由。我尝试更改这些插件的加载顺序(将 storage-plugin 移至最后),行为是相同的。

我的app.routes.ts模块中有以下路线。

export const routes: Route[] = [
{
  path: 'login',
  children: AUTH_ROUTES
},
{
  path: 'account-verification',
  loadChildren: 'app/account-verification/account-verification.module#AccountVerificationModule'
},
{
  path: 'profile',
  loadChildren: 'app/profile/profile.module#ProfileModule'
},
{
  path: '',
  component: LayoutComponent,
  children: [
    { path: '', loadChildren: 'app/user-dashboard/user-dashboard.module#UserDashboardModule' },
    { path: 'calendar', loadChildren: 'app/calendar/calendar.module#CalendarModule' },
    // { path: 'messages', loadChildren: 'app/messaging/messaging.module#MessagingModule' },
  ],
  canActivate: [ guards.AuthGuard, guards.AccountVerificationGuard ]
}
];

我可以毫无问题地从/profile/create(ProfileModule 中的子路由)导航到login

单击按钮转到使用的路线[routerLink]仍然有效,但如果我打开/profile/create/login在浏览器中输入,我会立即返回到/profile/create. 这是我的进口app.module.ts

imports: [
BrowserModule,
AuthModule,
CoreModule,
HttpClientModule,
LayoutModule,
AngularFontAwesomeModule,
RouterModule.forRoot(routes, { enableTracing: true }),
NgxsModule.forRoot([]),
NgxsReduxDevtoolsPluginModule.forRoot(),
NgxsStoragePluginModule.forRoot(),
NgxsRouterPluginModule.forRoot(),
ToastrModule.forRoot({
  timeOut: 10000,
  positionClass: 'toast-top-right',
  preventDuplicates: true,
}),
ToastContainerModule,
BrowserAnimationsModule,
FileUploadModule
],

包.json

"dependencies": {
  "@angular/animations": "6.0.4",
  "@angular/cdk": "6.2.1",
  "@angular/common": "6.0.4",
  "@angular/compiler": "6.0.4",
  "@angular/core": "6.0.4",
  "@angular/forms": "6.0.4",
  "@angular/http": "6.0.4",
  "@angular/material": "6.2.1",
  "@angular/platform-browser": "6.0.4",
  "@angular/platform-browser-dynamic": "6.0.4",
  "@angular/router": "6.0.4",
  "@ngxs/router-plugin": "3.1.3",
  "@ngxs/storage-plugin": "3.1.3",
  "@ngxs/store": "3.1.3",
4

1 回答 1

0

我在 NXGXS 社区和 NGXS 文档上得到了什么。这是 NGXS 中的错误,但在存储插件模块中提及节点作为选项键有一个临时解决方案。

就像评论中提到的@Ryan 一样。

NgxsStoragePluginModule.forRoot({ key: ['auth'] })

但在上述解决方案中,您需要提及所有要序列化的节点。

在开发通道中它是固定的,您可以将包更新到@ngxs/store@dev并且这将是固定的。将软件包更新为 dev 解决了我的问题。

在这里您可以看到更改日志。 NGXS 的更改日志

于 2019-05-15T14:04:42.283 回答