Skip to content

Commit 7673ff6

Browse files
committed
Add router without insertBefore in router-outlet
1 parent 24fd9c3 commit 7673ff6

File tree

11 files changed

+233
-20
lines changed

11 files changed

+233
-20
lines changed

package-lock.json

Lines changed: 43 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
},
1919
"private": true,
2020
"dependencies": {
21-
"@angular/animations": "~8.2.11",
21+
"@angular/animations": "^8.2.14",
22+
"@angular/cdk": "^8.2.3",
2223
"@angular/common": "~8.2.11",
2324
"@angular/compiler": "~8.2.11",
24-
"@angular/core": "~8.2.11",
25+
"@angular/core": "^8.2.14",
2526
"@angular/forms": "~8.2.11",
27+
"@angular/material": "^8.2.3",
2628
"@angular/platform-browser": "~8.2.11",
2729
"@angular/platform-browser-dynamic": "~8.2.11",
2830
"@angular/router": "~8.2.11",

projects/angular-nodegui/src/lib/nodegui-lib.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import {
99
import { NodeguiRendererFactory } from './renderer';
1010
import { QWindowService } from './window';
1111
import { ComponentsMap } from './components/components-map';
12+
import {
13+
ViewportScroller,
14+
ɵNullViewportScroller as NullViewportScroller
15+
} from '@angular/common';
1216

1317
@Injectable()
1418
export class NodeguiErrorHandler implements ErrorHandler {
@@ -27,7 +31,8 @@ export class NodeguiErrorHandler implements ErrorHandler {
2731
useClass: NodeguiRendererFactory,
2832
deps: [QWindowService, ComponentsMap]
2933
},
30-
{ provide: ErrorHandler, useClass: NodeguiErrorHandler }
34+
{ provide: ErrorHandler, useClass: NodeguiErrorHandler },
35+
{ provide: ViewportScroller, useClass: NullViewportScroller }
3136
]
3237
})
3338
export class NodeguiLibModule {}

projects/angular-nodegui/src/lib/renderer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ export class NodeguiRenderer implements Renderer2 {
8888
destroy(): void {}
8989

9090
insertBefore(parent: NgComponent, newChild: any, refChild: any): void {
91+
// TODO: insert before for router-outlet
92+
console.log('insertBefore');
93+
console.log(parent, newChild, refChild);
94+
9195
parent.insertBefore(newChild, refChild);
9296
}
9397

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Injectable } from '@angular/core';
2+
import { LocationStrategy, LocationChangeListener } from '@angular/common';
3+
import { UrlTree, DefaultUrlSerializer } from '@angular/router';
4+
5+
@Injectable()
6+
export class NodeGuiLocationStrategy extends LocationStrategy {
7+
private popStateCallbacks = new Array<(_: any) => any>();
8+
private currentUrlTree: UrlTree;
9+
10+
path(includeHash?: boolean): string {
11+
return '/';
12+
}
13+
prepareExternalUrl(internal: string): string {
14+
return internal;
15+
}
16+
pushState(state: any, title: string, url: string, queryParams: string): void {
17+
const urlSerializer = new DefaultUrlSerializer();
18+
this.currentUrlTree = urlSerializer.parse(url);
19+
const urlTreeRoot = this.currentUrlTree.root;
20+
}
21+
replaceState(
22+
state: any,
23+
title: string,
24+
url: string,
25+
queryParams: string
26+
): void {}
27+
forward(): void {
28+
throw new Error('Method not implemented.');
29+
}
30+
back(): void {
31+
throw new Error('Method not implemented.');
32+
}
33+
onPopState(fn: LocationChangeListener): void {
34+
this.popStateCallbacks.push(fn);
35+
}
36+
getBaseHref(): string {
37+
return '';
38+
}
39+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Injectable } from '@angular/core';
2+
import { PlatformLocation, LocationChangeListener } from '@angular/common';
3+
import { NodeGuiLocationStrategy } from './location-strategy';
4+
5+
@Injectable()
6+
export class NodeguiPlatformLocation extends PlatformLocation {
7+
constructor(private locationStrategy: NodeGuiLocationStrategy) {
8+
super();
9+
}
10+
11+
getState(): any {
12+
return undefined;
13+
}
14+
15+
// tslint:disable-next-line:member-ordering
16+
readonly hostname: string;
17+
// tslint:disable-next-line:member-ordering
18+
readonly href: string;
19+
// tslint:disable-next-line:member-ordering
20+
readonly port: string;
21+
// tslint:disable-next-line:member-ordering
22+
readonly protocol: string;
23+
24+
getBaseHrefFromDOM(): string {
25+
return '/';
26+
}
27+
28+
onPopState(fn: LocationChangeListener): void {
29+
this.locationStrategy.onPopState(fn);
30+
}
31+
32+
onHashChange(fn: LocationChangeListener): void {}
33+
34+
get search(): string {
35+
return '';
36+
}
37+
get hash(): string {
38+
return '';
39+
}
40+
get pathname(): string {
41+
return this.locationStrategy.path();
42+
}
43+
set pathname(newPath: string) {
44+
throw new Error('NodeguiPlatformLocation set pathname - not implemented');
45+
}
46+
47+
pushState(state: any, title: string, url: string): void {
48+
this.locationStrategy.pushState(state, title, url, null);
49+
}
50+
51+
replaceState(state: any, title: string, url: string): void {
52+
this.locationStrategy.replaceState(state, title, url, null);
53+
}
54+
55+
forward(): void {
56+
throw new Error('NodeguiPlatformLocation.forward() - not implemented');
57+
}
58+
59+
back(): void {
60+
this.locationStrategy.back();
61+
}
62+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {
2+
NgModule,
3+
Optional,
4+
SkipSelf,
5+
NO_ERRORS_SCHEMA,
6+
ModuleWithProviders
7+
} from '@angular/core';
8+
import { NodeGuiLocationStrategy } from './location-strategy';
9+
import { LocationStrategy, PlatformLocation } from '@angular/common';
10+
import { NodeguiPlatformLocation } from './platform-location';
11+
import { RouterModule, Routes, ExtraOptions } from '@angular/router';
12+
13+
const NS_ROUTER_PROVIDERS = [
14+
{
15+
provide: NodeGuiLocationStrategy,
16+
useFactory: provideLocationStrategy,
17+
deps: [[NodeGuiLocationStrategy, new Optional(), new SkipSelf()]]
18+
},
19+
{ provide: LocationStrategy, useExisting: NodeGuiLocationStrategy },
20+
NodeguiPlatformLocation,
21+
{ provide: PlatformLocation, useExisting: NodeguiPlatformLocation }
22+
];
23+
24+
@NgModule({
25+
imports: [RouterModule],
26+
exports: [RouterModule],
27+
schemas: [NO_ERRORS_SCHEMA]
28+
})
29+
export class NodeguiRouterModule {
30+
static forRoot(
31+
routes: Routes,
32+
config?: ExtraOptions
33+
): ModuleWithProviders<NodeguiRouterModule> {
34+
return {
35+
ngModule: NodeguiRouterModule,
36+
providers: [
37+
...RouterModule.forRoot(routes, config).providers,
38+
...NS_ROUTER_PROVIDERS
39+
]
40+
};
41+
}
42+
43+
static forChild(routes: Routes): ModuleWithProviders<NodeguiRouterModule> {
44+
return {
45+
ngModule: NodeguiRouterModule,
46+
providers: RouterModule.forChild(routes).providers
47+
};
48+
}
49+
}
50+
51+
export function provideLocationStrategy(
52+
locationStrategy: NodeGuiLocationStrategy
53+
): NodeGuiLocationStrategy {
54+
return locationStrategy ? locationStrategy : new NodeGuiLocationStrategy();
55+
}

projects/angular-nodegui/src/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './lib/platform-dynamic';
66
export * from './lib/platform-static';
77
export * from './lib/nodegui-lib.module';
88
export * from './lib/http-fetch-backend';
9+
export * from './lib/router/router.module';

src/app/app.component.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
<view id="app">
33
<image id="image" [src]="'./src/assets/angular.png'" [aspectRatioMode]="aspectRatioMode"></image>
44

5-
<app-hello [name]="name"></app-hello>
5+
<!-- <app-hello [name]="name"></app-hello> -->
66

77
<text>Github username</text>
88
<linedit [text]="name" [placeholderText]="'Insert github username'" (textChanged)="textChanged($event)"></linedit>
99

10+
<button (clicked)="setRoute()">
11+
to home route
12+
</button>
1013
<!-- <checkbox [checked]="true"></checkbox>
1114
<checkbox [checked]="true" [enabled]="false"></checkbox>
15+
1216
<button [style.background-color]="'green'" (clicked)="setName()">
1317
Green button
1418
</button>
@@ -22,5 +26,6 @@
2226
[value]="20"
2327
>
2428
</spinbox> -->
29+
<router-outlet></router-outlet>
2530
</view>
2631
</window>

0 commit comments

Comments
 (0)