Skip to content

Commit

Permalink
feat: allow paths without leading slash (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Jul 23, 2020
1 parent 654139a commit 03ad384
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion libs/angular-routing/src/lib/route.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,21 @@ export function getRouteParams(routeComponent: RouteComponent) {
})
export class RouteComponent implements OnInit, OnDestroy {
@ContentChild(TemplateRef) template: TemplateRef<any> | null;
@Input() path: string;
@Input()
get path() {
return this._path;
}
set path(value: string) {
this._path = this.sanitizePath(value);
}
@Input() component: Type<any>;
@Input() load: Load;
@Input() reuse = true;
@Input() redirectTo!: string;
@Input() exact: boolean;
@Input() routeOptions: RouteOptions;

private _path: string;
private destroy$ = new Subject();
private _routeParams$ = new BehaviorSubject<Params>({});
private _shouldRender$ = new BehaviorSubject<boolean>(false);
Expand Down Expand Up @@ -197,4 +204,9 @@ export class RouteComponent implements OnInit, OnDestroy {
this.hideTemplate();
}
}

private sanitizePath(path: string): string {
const trimmed = path.trim();
return trimmed.startsWith('/') ? trimmed : `/${trimmed}`;
}
}

0 comments on commit 03ad384

Please sign in to comment.