-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app): navigation links do not work when using baseHref
Closes #34
- Loading branch information
1 parent
8618d77
commit 41f4c3f
Showing
17 changed files
with
125 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './page-link.component'; | ||
export * from './page-link.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"lib": { | ||
"entryFile": "index.ts" | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<a [class]="classes" [routerLink]="path" [fragment]="fragment" *ngIf="!isExternalLink"> | ||
<ng-container *ngTemplateOutlet="content"></ng-container> | ||
</a> | ||
|
||
<a [class]="classes" [href]="path" *ngIf="isExternalLink" target="_blank"> | ||
<ng-container *ngTemplateOutlet="content"></ng-container> | ||
</a> | ||
|
||
<ng-template #content> | ||
<ng-content></ng-content> | ||
</ng-template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {ChangeDetectionStrategy, Component, HostBinding, Input} from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'ng-doc-page-link', | ||
templateUrl: './page-link.component.html', | ||
styleUrls: ['./page-link.component.css'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class NgDocPageLinkComponent { | ||
@Input() | ||
href: string = ''; | ||
|
||
@Input() | ||
classes: string = ''; | ||
|
||
get isExternalLink(): boolean { | ||
return this.href.startsWith('http'); | ||
} | ||
|
||
get path(): string { | ||
return this.href.split('#')[0]; | ||
} | ||
|
||
get fragment(): string { | ||
return this.href.split('#')[1]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {CommonModule} from '@angular/common'; | ||
import {NgModule} from '@angular/core'; | ||
import {RouterLink} from '@angular/router'; | ||
|
||
import {NgDocPageLinkComponent} from './page-link.component'; | ||
|
||
@NgModule({ | ||
declarations: [NgDocPageLinkComponent], | ||
imports: [CommonModule, RouterLink], | ||
exports: [NgDocPageLinkComponent], | ||
}) | ||
export class NgDocPageLinkModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './link-processor.directive'; | ||
export * from './link-processor.module'; |
26 changes: 26 additions & 0 deletions
26
libs/app/processors/link-processor/link-processor.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {Directive, ElementRef, ViewContainerRef} from '@angular/core'; | ||
import {NgDocPageLinkComponent} from '@ng-doc/app/components/page-link'; | ||
import {NgDocProcessorOptions} from '@ng-doc/app/interfaces'; | ||
import {NgDocHtmlProcessor} from '@ng-doc/app/processors/html-processor'; | ||
|
||
@Directive({ | ||
selector: '[ngDocLinkProcessor]', | ||
}) | ||
export class NgDocLinkProcessorDirective extends NgDocHtmlProcessor<NgDocPageLinkComponent> { | ||
constructor( | ||
protected override readonly elementRef: ElementRef<HTMLElement>, | ||
protected override readonly viewContainerRef: ViewContainerRef, | ||
) { | ||
super(elementRef, viewContainerRef, `a`, NgDocPageLinkComponent); | ||
} | ||
|
||
protected override extractComponentOptions(element: Element): NgDocProcessorOptions<NgDocPageLinkComponent> { | ||
return { | ||
inputs: { | ||
href: element.getAttribute('href') ?? '', | ||
classes: element.getAttribute('class') ?? '', | ||
}, | ||
content: [Array.from(element.childNodes)], | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {NgModule} from '@angular/core'; | ||
|
||
import {NgDocLinkProcessorDirective} from './link-processor.directive'; | ||
|
||
@NgModule({ | ||
declarations: [NgDocLinkProcessorDirective], | ||
exports: [NgDocLinkProcessorDirective], | ||
}) | ||
export class NgDocLinkProcessorModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"lib": { | ||
"entryFile": "index.ts" | ||
} | ||
} |