Skip to content

Commit 35738d2

Browse files
committed
nested routers example
1 parent cf3e8c0 commit 35738d2

12 files changed

+148
-1
lines changed

app/app.routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,10 @@ export const routes = [
229229
path: "platform",
230230
loadChildren: "./platform/platform-examples.module#PlatformExamplesModule",
231231
data: { title: "Platform Module" }
232+
},
233+
{
234+
path: "routing",
235+
loadChildren: "./routing/routing-examples.module#RoutingExamplesModule",
236+
data: { title: "Angular routing" }
232237
}
233238
];

app/examples-list.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ let mainMenuLinks = [
4545
new Link("DataEntry (extended examples)", "/dataentry"),
4646
new Link("User Profile (extended examples)", "/userprofile"),
4747
new Link("Content Screens", "/content-screens"),
48-
new Link("Camera", "/camera")
48+
new Link("Camera", "/camera"),
49+
new Link("Angular routing", "/routing")
4950
];
5051

5152
@Component({
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Common scenario is to use nested router outlets. In NativeScript + Angular-2 you can
2+
nest `router-outlet` within other `router-outlet` or within `page-router-outlet`.
3+
4+
Module
5+
```
6+
export const routerConfig = [
7+
{
8+
path: "",
9+
component: RoutingExamplesComponent
10+
},
11+
{
12+
path: "nested-routers",
13+
component: NestedRoutersComponent,
14+
children: [
15+
{ path: "first", component: SubRouteOneComponent },
16+
{ path: "second", component: SubRouteTwoComponent }
17+
]
18+
}
19+
];
20+
```
21+
22+
HTML
23+
<snippet id='nested-router-html'/>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- >> nested-router-html -->
2+
<StackLayout sdkExampleTitle sdkToggleNavButton>
3+
<GridLayout rows="80" columns="*, *">
4+
<Button text="First" [nsRouterLink]="['first']" class="btn btn-primary btn-active" col="0"></Button>
5+
<Button text="Second" [nsRouterLink]="['second']" class="btn btn-primary btn-active" col="1"></Button>
6+
</GridLayout>
7+
<router-outlet></router-outlet>
8+
</StackLayout>
9+
<!-- << nested-router-html -->
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Component } from "@angular/core";
2+
3+
@Component({
4+
moduleId: module.id,
5+
templateUrl: "./nested-routers.component.html"
6+
})
7+
export class NestedRoutersComponent {
8+
constructor() { }
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<GridLayout rows="auto, *">
2+
<Label row="0" text="Loaded inside the nested router" textWrap="true" class="m-16 text-center"></Label>
3+
<Button row="1" text="This is FIRST. Load SECOND" [nsRouterLink]="['/routing/nested-routers/second']" class="btn btn-primary btn-active"></Button>
4+
</GridLayout>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// >>
2+
import { Component } from "@angular/core";
3+
4+
@Component({
5+
moduleId: module.id,
6+
templateUrl: "./sub-route-one.component.html"
7+
})
8+
export class SubRouteOneComponent {
9+
constructor() { }
10+
}
11+
// <<
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<GridLayout rows="auto, *">
2+
<Label row="0" text="Loaded inside the nested router" textWrap="true" class="m-16 text-center"></Label>
3+
<Button row="1" text="This is SECOND. Load FIRST" [nsRouterLink]="['/routing/nested-routers/first']" class="btn btn-primary btn-active"></Button>
4+
</GridLayout>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// >>
2+
import { Component } from "@angular/core";
3+
4+
@Component({
5+
moduleId: module.id,
6+
templateUrl: "./sub-route-two.component.html"
7+
})
8+
export class SubRouteTwoComponent {
9+
constructor() { }
10+
}
11+
// <<

app/routing/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Angular 2 routing techniques

0 commit comments

Comments
 (0)