Skip to content

Commit a032115

Browse files
committed
Port the rest of the router examples to rc5.
1 parent a735506 commit a032115

File tree

4 files changed

+81
-74
lines changed

4 files changed

+81
-74
lines changed

ng-sample/app/app.ts

+33-31
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,24 @@ trace.setCategories(routerTraceCategory);
2121
// trace.setCategories(listViewTraceCategory);
2222
trace.enable();
2323

24-
import {RendererTest} from './examples/renderer-test';
25-
import {TabViewTest} from './examples/tab-view/tab-view-test';
26-
import {Benchmark} from './performance/benchmark';
27-
import {ListTest} from './examples/list/list-test';
28-
import {ListTestAsync, ListTestFilterAsync} from "./examples/list/list-test-async";
29-
import {ImageTest} from "./examples/image/image-test";
30-
import {HttpTest} from "./examples/http/http-test";
31-
import {ActionBarTest} from "./examples/action-bar/action-bar-test";
32-
import {ModalTest} from "./examples/modal/modal-test";
33-
import {PlatfromDirectivesTest} from "./examples/platform-directives/platform-directives-test";
34-
import {LivesyncApp, LivesyncTestRouterProviders} from "./examples/livesync-test/livesync-test-app";
35-
24+
import { RendererTest } from './examples/renderer-test';
25+
import { TabViewTest } from './examples/tab-view/tab-view-test';
26+
import { Benchmark } from './performance/benchmark';
27+
import { ListTest } from './examples/list/list-test';
28+
import { ListTestAsync, ListTestFilterAsync } from "./examples/list/list-test-async";
29+
import { ImageTest } from "./examples/image/image-test";
30+
import { HttpTest } from "./examples/http/http-test";
31+
import { ActionBarTest } from "./examples/action-bar/action-bar-test";
32+
import { ModalTest } from "./examples/modal/modal-test";
33+
import { PlatfromDirectivesTest } from "./examples/platform-directives/platform-directives-test";
34+
import { LivesyncApp, LivesyncTestRouterProviders } from "./examples/livesync-test/livesync-test-app";
3635

3736
// new router
3837
import { RouterOutletAppComponent } from "./examples/router/router-outlet-test";
3938
import { PageRouterOutletAppComponent } from "./examples/router/page-router-outlet-test";
40-
import { PageRouterOutletNestedAppComponent, PageRouterOutletNestedRouterProviders } from "./examples/router/page-router-outlet-nested-test";
41-
import { ClearHistoryAppComponent, ClearHistoryRouterProviders } from "./examples/router/clear-history-test";
42-
import { LoginAppComponent, LoginExampleProviders } from "./examples/router/login-test";
39+
import { PageRouterOutletNestedAppComponent } from "./examples/router/page-router-outlet-nested-test";
40+
import { ClearHistoryAppComponent } from "./examples/router/clear-history-test";
41+
import { LoginAppComponent } from "./examples/router/login-test";
4342

4443
// animations
4544
import { AnimationEnterLeaveTest } from "./examples/animation/animation-enter-leave-test";
@@ -50,15 +49,6 @@ import { AnimationStatesTest } from "./examples/animation/animation-states-test"
5049
// nativeScriptBootstrap(HttpTest);
5150
//nativeScriptBootstrap(ActionBarTest, [NS_ROUTER_PROVIDERS_DEPRECATED], { startPageActionBarHidden: false });
5251
//nativeScriptBootstrap(ActionBarTest, [NS_ROUTER_PROVIDERS_DEPRECATED]);
53-
//nativeScriptBootstrap(ModalTest);
54-
//nativeScriptBootstrap(PlatfromDirectivesTest);
55-
56-
// new router
57-
//nativeScriptBootstrap(RouterOutletAppComponent, [RouterOutletRouterProviders]);
58-
// nativeScriptBootstrap(PageRouterOutletAppComponent, [PageRouterOutletRouterProviders]);
59-
// nativeScriptBootstrap(PageRouterOutletNestedAppComponent, [PageRouterOutletNestedRouterProviders]);
60-
// nativeScriptBootstrap(ClearHistoryAppComponent, [ClearHistoryRouterProviders]);
61-
// nativeScriptBootstrap(LoginAppComponent, [LoginExampleProviders]);
6252

6353
@NgModule({
6454
declarations: [
@@ -77,20 +67,25 @@ import { AnimationStatesTest } from "./examples/animation/animation-states-test"
7767
})
7868
class ExampleModule {}
7969

80-
function makeExampleModule(componentType, routes = null, entryComponents = null) {
70+
function makeExampleModule(componentType) {
8171
let imports: any[] = [ExampleModule];
82-
if (routes) {
83-
imports.push(NativeScriptRouterModule.forRoot(routes))
72+
if (componentType.routes) {
73+
imports.push(NativeScriptRouterModule.forRoot(componentType.routes))
8474
}
8575
let entries = [];
86-
if (entryComponents) {
87-
entries = entryComponents;
76+
if (componentType.entries) {
77+
entries = componentType.entries;
78+
}
79+
let providers = [];
80+
if (componentType.providers) {
81+
providers = componentType.providers
8882
}
8983
@NgModule({
9084
bootstrap: [componentType],
9185
imports: imports,
9286
entryComponents: entries,
9387
declarations: entries,
88+
providers: providers,
9489
})
9590
class ExampleModuleForComponent {}
9691

@@ -103,8 +98,15 @@ function makeExampleModule(componentType, routes = null, entryComponents = null)
10398
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTest));
10499
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ListTestAsync));
105100
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ImageTest));
106-
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(RouterOutletAppComponent, RouterOutletAppComponent.routes));
107-
platformNativeScriptDynamic().bootstrapModule(makeExampleModule(PageRouterOutletAppComponent, PageRouterOutletAppComponent.routes, PageRouterOutletAppComponent.entries));
101+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ModalTest));
102+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(PlatfromDirectivesTest));
103+
104+
//new router
105+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(RouterOutletAppComponent));
106+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(PageRouterOutletAppComponent));
107+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(PageRouterOutletNestedAppComponent));
108+
//platformNativeScriptDynamic().bootstrapModule(makeExampleModule(ClearHistoryAppComponent));
109+
platformNativeScriptDynamic().bootstrapModule(makeExampleModule(LoginAppComponent));
108110

109111
// Livesync test
110112
// var cahcedUrl: string;

ng-sample/app/examples/router/clear-history-test.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,17 @@ class ThirdComponent implements OnInit, OnDestroy {
9393
providers: [LocationLogService],
9494
template: `<page-router-outlet></page-router-outlet>`
9595
})
96-
export class ClearHistoryAppComponent { }
96+
export class ClearHistoryAppComponent {
97+
static routes: RouterConfig = [
98+
{ path: "", redirectTo: "/first", terminal: true },
99+
{ path: "first", component: FirstComponent },
100+
{ path: "second", component: SecondComponent },
101+
{ path: "third", component: ThirdComponent },
102+
];
97103

98-
const routes: RouterConfig = [
99-
{ path: "", redirectTo: "/first", terminal: true },
100-
{ path: "first", component: FirstComponent },
101-
{ path: "second", component: SecondComponent },
102-
{ path: "third", component: ThirdComponent },
103-
];
104-
105-
export const ClearHistoryRouterProviders = [
106-
nsProvideRouter(routes, { enableTracing: false })
107-
];
104+
static entries = [
105+
FirstComponent,
106+
SecondComponent,
107+
ThirdComponent,
108+
]
109+
}

ng-sample/app/examples/router/login-test.ts

+17-16
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class LoginService {
4141

4242
@Component({
4343
selector: 'login',
44-
directives: [NS_ROUTER_DIRECTIVES],
4544
styleUrls: ["examples/router/styles.css"],
4645
template: `
4746
<StackLayout>
@@ -70,7 +69,6 @@ class LoginComponent {
7069

7170
@Component({
7271
selector: 'main',
73-
directives: [NS_ROUTER_DIRECTIVES],
7472
styleUrls: ["examples/router/styles.css"],
7573
template: `
7674
<StackLayout>
@@ -115,19 +113,22 @@ class AuthGuard implements CanActivate {
115113

116114
@Component({
117115
selector: 'navigation-test',
118-
directives: [NS_ROUTER_DIRECTIVES],
119116
template: `<page-router-outlet></page-router-outlet>`
120117
})
121-
export class LoginAppComponent { }
122-
123-
const routes: RouterConfig = [
124-
{ path: "", redirectTo: "/main", terminal: true },
125-
{ path: "main", component: MainComponent, canActivate: [AuthGuard] },
126-
{ path: "login", component: LoginComponent },
127-
];
128-
129-
export const LoginExampleProviders = [
130-
LoginService,
131-
AuthGuard,
132-
nsProvideRouter(routes, { enableTracing: false })
133-
];
118+
export class LoginAppComponent {
119+
static routes: RouterConfig = [
120+
{ path: "", redirectTo: "/main", terminal: true },
121+
{ path: "main", component: MainComponent, canActivate: [AuthGuard] },
122+
{ path: "login", component: LoginComponent },
123+
]
124+
125+
static entries = [
126+
MainComponent,
127+
LoginComponent
128+
]
129+
130+
static providers = [
131+
AuthGuard,
132+
LoginService,
133+
]
134+
}

ng-sample/app/examples/router/page-router-outlet-nested-test.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,27 @@ class SecondComponent implements OnInit, OnDestroy {
125125
template: `<page-router-outlet></page-router-outlet>`
126126
})
127127
export class PageRouterOutletNestedAppComponent {
128+
static routes: RouterConfig = [
129+
{ path: "", component: FirstComponent },
130+
{
131+
path: "second/:depth", component: SecondComponent,
132+
children: [
133+
{ path: "", component: MasterComponent },
134+
{ path: "detail/:id", component: DetailComponent }
135+
]
136+
},
137+
];
138+
139+
static entries = [
140+
FirstComponent,
141+
SecondComponent,
142+
MasterComponent,
143+
DetailComponent
144+
]
145+
128146
constructor(router: Router, private location: Location) {
129147
router.events.subscribe((e) => {
130148
console.log("--EVENT-->: " + e.toString());
131149
})
132150
}
133151
}
134-
135-
136-
const routes: RouterConfig = [
137-
{ path: "", component: FirstComponent },
138-
{
139-
path: "second/:depth", component: SecondComponent,
140-
children: [
141-
{ path: "", component: MasterComponent },
142-
{ path: "detail/:id", component: DetailComponent }
143-
]
144-
},
145-
];
146-
147-
export const PageRouterOutletNestedRouterProviders = [
148-
nsProvideRouter(routes, { enableTracing: false })
149-
];

0 commit comments

Comments
 (0)