Last active
February 2, 2021 15:54
-
-
Save anein/fba647b4206695d109c30e1fc0d2e8ee to your computer and use it in GitHub Desktop.
Angular2 Router with the url matcher.
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
export function MyAwesomeMatcher ( url: UrlSegment[] ): UrlMatchResult { | |
if (url.length === 0) { | |
return null; | |
} | |
const reg = /^(awesome-path)$/; | |
const param = url[ 0 ].toString(); | |
if (param.match( reg )) { | |
// myValue: "awesome-path" | |
return ({ consumed: url, posParams: { myValue: url[ 0 ] } }); | |
} | |
return null; | |
} | |
// define application routes. | |
const routes: Routes = [ | |
{ path: '', component: HomeComponent, pathMatch: 'full' }, | |
// { path: 'awesome-path', component: MyAwesomeComponent }, | |
{ matcher: MyAwesomeMatcher, component: MyAwesomeComponent } | |
... | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For mine use case where a matcher can have optionally parameter