简体   繁体   English

Angular Nativescript 无法在惰性模块中导航

[英]Angular Nativescript can't navigate in lazy module

Template I used : Nativescript-Tabs-Template我使用的模板: Nativescript-Tabs-Template

When I try to navigate to sibling component (both are in one lazy module) with:当我尝试导航到同级组件(​​两者都在一个惰性模块中)时:

 showItem() {
    this.routerExtensions.navigate(["details/"]);
}

(also done this - not sure if this is ok ) : (也这样做了 - 不确定这是否可以):

this.routerExtensions.navigate(["details", { outlets: { searchTab: ['details'] } }]);

I get the error :我收到错误:

Error: Cannot match any routes.错误:无法匹配任何路由。 URL Segment: 'details' URL 段:“详细信息”

*But when I navigate with nsRouterLink it works: * *但是当我使用 nsRouterLink 导航时,它可以工作:*

<Label text="this works" [nsRouterLink]="['/details']></Label>

App.components.html Tab : App.components.html 标签:

<TabView androidTabsPosition="bottom">
    <page-router-outlet
    *tabItem="{title: 'Search', iconSource: getIconSource('search')}"
    name="searchTab">
    </page-router-outlet>
</TabView>

Router.module.ts : Router.module.ts :

const routes: Routes = [
{
    path: "",
    redirectTo: "/(homeTab:home/default//browseTab:browse/default//searchTab:search/default)",
    pathMatch: "full"
},
    {
        path: "search",
        component: NSEmptyOutletComponent,
        loadChildren: "~/app/search/search.module#SearchModule",
        outlet: "searchTab"
    }
]

Search.module.ts : Search.module.ts :

import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptCommonModule } from "nativescript-angular/common";

import { SearchRoutingModule } from "./search-routing.module";
import { SearchComponent } from "./search.component";
import { NgShadowModule } from 'nativescript-ng-shadow';
import { NativeScriptFormsModule } from "nativescript-angular/forms";
import { LabelMaxLinesDirective } from "../directives/label-max-lines.directive";
import { ItemDetailComponent } from "./item-detail/item-detail.component";

@NgModule({
    imports: [
        NativeScriptCommonModule,
        SearchRoutingModule,
        NgShadowModule,
        NativeScriptFormsModule,
    ],
    declarations: [
        SearchComponent,
        LabelMaxLinesDirective,
        ItemDetailComponent
    ],
    schemas: [
        NO_ERRORS_SCHEMA
    ]
})
export class SearchModule { }

Search.router.module.ts : Search.router.module.ts :

import { NgModule } from "@angular/core";
import { Routes } from "@angular/router";
import { NativeScriptRouterModule } from "nativescript-angular/router";

import { SearchComponent } from "./search.component";
import { ItemDetailComponent } from "./item-detail/item-detail.component";

const routes: Routes = [
    { path: "default", component: SearchComponent },
    { path: "details", component: ItemDetailComponent }
];

@NgModule({
    imports: [NativeScriptRouterModule.forChild(routes)],
    exports: [NativeScriptRouterModule]
})
export class SearchRoutingModule { }

What Am I doing wrong ?我究竟做错了什么 ?

NativeScript Tabs Template is no longer recommended.不再推荐 NativeScript 标签模板。 Use this tutorial from NativeScript Blog:使用 NativeScript 博客中的本教程:

https://www.nativescript.org/blog/implementing-a-login-for-nativescript-apps-with-tab-based-navigation https://www.nativescript.org/blog/implementing-a-login-for-nativescript-apps-with-tab-based-navigation

And its example in GitHub:以及它在 GitHub 中的示例:

https://github.com/NativeScript/login-tab-navigation-ng https://github.com/NativeScript/login-tab-navigation-ng

In this example each tab has its own navigation tree and you can go back and forward independently (Like Facebook app does).在这个例子中,每个选项卡都有自己的导航树,你可以独立地后退和前进(就像 Facebook 应用程序那样)。 Inside tabs every navigation is relative, so don't use something like ['/foo'] .在选项卡内,每个导航都是相对的,所以不要使用['/foo']

constructor(
  private route: ActivatedRoute,
  private router: RouterExtensions
) { }

goForward() {
  const navigation: ExtendedNavigationExtras = {
    relativeTo: this.route,
    transition: {
    name: 'slide'
    }
  };

  this.router.navigate(['../foo'], navigation);
}

goBack() {
  this.router.back();
}

have you tried this this.routerExtensions.navigate(["/search/details"]);你试过这个this.routerExtensions.navigate(["/search/details"]); include the parent route path before its child path在其子路径之前包含父路由路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM