UrlMatcher
一个用于匹配路由和 URL 的函数。 当 path
和 pathMatch
的组合不足以表达时,可以为 Route.matcher
实现一个自定义的 URL 匹配器。
A function for matching a route against URLs. Implement a custom URL matcher for Route.matcher
when a combination of path
and pathMatch
is not expressive enough. Cannot be used together with path
and pathMatch
.
type UrlMatcher = (segments: UrlSegment[], group: UrlSegmentGroup, route: Route) => UrlMatchResult;
使用说明
下列匹配器会匹配 HTML 文件。
The following matcher matches HTML files.
export function htmlFiles(url: UrlSegment[]) {
return url.length === 1 && url[0].path.endsWith('.html') ? ({consumed: url}) : null;
}
export const routes = [{ matcher: htmlFiles, component: AnyComponent }];