【问题标题】:NativeScript ListView items disappear after routing back to BottomNavigation componentNativeScript ListView 项目在路由回 BottomNavigation 组件后消失
【发布时间】:2019-12-02 22:25:02
【问题描述】:

在我的 NativeScript 应用程序中,有一个 BottomNavigation 选项卡:

const routes: Routes = [
    {
        path: 'tabs',
        component: TabsComponent,
        children: [
            {
                path: 'feed',
                loadChildren: '~/app/pages/feed/feed.module#FeedModule',
                component: NSEmptyOutletComponent,
                outlet: 'feedTab'
            },
            {
                path: 'notification',
                loadChildren: '~/app/pages/notification/notification.module#NotificationModule',
                component: NSEmptyOutletComponent,
                outlet: 'notificationTab'
            },
            {
                path: 'create',
                loadChildren: '~/app/pages/create/create.module#CreateModule',
                component: NSEmptyOutletComponent,
                outlet: 'createTab'
            },
            {
                path: 'profile',
                loadChildren: '~/app/pages/profile/profile.module#ProfileModule',
                component: NSEmptyOutletComponent,
                outlet: 'profileTab'
            }
        ]
    }
];

在其中一个子选项卡中,有一个 RadListView 项目:

<ActionBar id="profile-action-bar" title="Notifications"></ActionBar>
<GridLayout>
  <RadListView separatorColor="transparent" class="notification-list" [items]="notificationList"
    (loadMoreDataRequested)="onLoadMoreItemsRequested($event)" loadOnDemandMode="Auto"
    (itemTap)="onNotificationTap($event)">
    <!-- (itemTap)="onGoalTap($event)" -->

    <ng-template let-item="item" let-i="index">
      <ns-notification-item [item]=item [position]=i></ns-notification-item>
    </ng-template>

  </RadListView>
</GridLayout>

导航到该选项卡时,列表会按预期填充,但如果您导航到另一个选项卡的子组件,然后直接返回到底部导航:

子组件:

this.router.navigate([
     '../tabs'
  ]);

ListView 中之前加载的所有项目都消失了...之前未加载的项目将开始填充列表

【问题讨论】:

  • 您是否尝试在 relativeTo 上传递 ActivatedRoute?你能分享一个可以重现问题的最小 Playground 示例吗?
  • @Manoj 这里是一个示例游乐场:play.nativescript.org/?template=play-ng&id=K3w4he&v=5 每当您在服务将项目加载到列表后从列表视图导航时,这些项目将“丢失”并且在您导航回时不会出现列表视图

标签: nativescript angular2-nativescript nativescript-angular


【解决方案1】:

Router Outlet 和 Page Router Outlet 有很大的不同。在 Web 上,当您导航时,当前路由上的所有组件都会被销毁,并会呈现导航路由的新组件。

使用移动应用程序,您可以保留导航堆栈,然后返回您离开的上一页。为此,您使用 Page Router Outlet,而要处理 Page Router Outlet,您需要 RouterExtensions

当你想回到历史的上一页时,你应该在RouterExtensions上调用back()方法。

Updated Playground

【讨论】:

猜你喜欢
  • 2018-07-04
  • 2021-07-25
  • 1970-01-01
  • 2017-04-24
  • 1970-01-01
  • 2021-02-16
  • 2018-06-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多