Reputation: 656
When I try the following:
const routes: Routes = [
{
path: "", component: RegisteredLayoutComponent, canActivate: [AuthGuard], children: [
{
path: '',
redirectTo:
"/(topicsTab:topicsPage//newsTab:newsPage//homeTab:homePage//askTab:askPage//moreTab:morePage)",
pathMatch: "full"
},
{ path: 'home', component: HomePageComponent, outlet: "homeTab" },...
{ path: '**', redirectTo: '' }
I get "Error: Cannot match any routes. URL Segment"
Am I doing something wrong? The page that contains the router outlets looks like:
<BottomNavigation selectedIndex="2">
<TabStrip backgroundColor="white">
<TabStripItem>
<Label text="Topics" class="icon__color"></Label>
<Image src="~/assets/round_people_black_18dp.png" class="fas t-36 icon__color"></Image>
</TabStripItem>
<TabStripItem class="special">
<Label text="News" class="icon__color"></Label>
<Image src="~/assets/round_local_library_black_18dp.png" class="fas t-36 icon__color"></Image>
</TabStripItem>
<TabStripItem class="special">
<Label text="Home" class="icon__color"></Label>
<Image src="~/assets/round_home_black_18dp.png" class="fas t-36 icon__color"></Image>
</TabStripItem>
<TabStripItem class="special">
<Label text="Ask?" class="icon__color"></Label>
<Image src="~/assets/round_contact_support_black_18dp.png" class="fas t-36 "></Image>
</TabStripItem>
<TabStripItem class="special">
<Label text="More" class="icon__color"></Label>
<Image src="~/assets/round_more_horiz_black_18dp.png" class="fas t-36 icon__color"></Image>
</TabStripItem>
</TabStrip>
<!-- The number of TabContentItem components should corespond to the number of TabStripItem components -->
<TabContentItem>
<page-router-outlet name="topicsTab"></page-router-outlet>
</TabContentItem>
<TabContentItem>
<page-router-outlet name="newsTab"></page-router-outlet>
</TabContentItem>
<TabContentItem>
<page-router-outlet name="homeTab"></page-router-outlet>
</TabContentItem>
<TabContentItem>
<page-router-outlet name="askTab"></page-router-outlet>
</TabContentItem>
<TabContentItem>
<page-router-outlet name="moreTab"></page-router-outlet>
</TabContentItem>
</BottomNavigation>
Can someone let me know what is the proper way to redirect?
Thanks!!!
Upvotes: 5
Views: 561
Reputation: 21908
Upon login you were trying to navigate relatively, but you are suppose to load a different module (as per your router setup, login is under unRegisteredRoute
and tabview is under registeredRoute
).
this.router.navigate(["/registeredRoute", { outlets: { topicsTab: ['topicsPage'], newsTab: ['newsPage'], homeTab: ['homePage'], askTab: ['askPage'], moreTab: ['morePage'] } }]);
Upvotes: 1
Reputation: 656
I got it :-) What really helped me get the right route was enabling tracing like so:
@NgModule({
imports: [NativeScriptRouterModule.forRoot(routes, { enableTracing: true })],
exports: [NativeScriptRouterModule]
})
One I could see the trace, I realized that I did not have the registeredRoute in the path of my redirect!
const routes: Routes = [
{ path: '', redirectTo: 'registeredRoute', pathMatch: 'full' },
{
path: "registeredRoute", component: RegisteredLayoutComponent, canActivate: [AuthGuard], children: [
{ path: "", component: HomeComponent, outlet: "homeTab" },
{ path: "homePage", component: HomeComponent, outlet: "homeTab" },
{ path: "topicsPage", component: TopicsComponent, outlet: "topicsTab" },
{ path: "newsPage", component: NewsComponent, outlet: "newsTab" },
{ path: "askPage", component: AskComponent, outlet: "askTab" },
{ path: "morePage", component: MoreComponent, outlet: "moreTab" }
]
},
{
path: "", component: UnregisteredLayoutComponent, children: [
{ path: '', redirectTo: 'loginPage', pathMatch: 'full' },
{ path: "loginPage", component: LoginComponent }
]
,
},
{ path: '**', redirectTo: '', pathMatch: 'full' }
];
Upvotes: 2