填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

UrlMatcher

一個用於匹配路由和 URL 的函式。 當 pathpathMatch 的組合不足以表達時,可以為 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 | null;
    

說明

該函式採用以下引數,並返回一個 UrlMatchResult 物件。

The function takes the following arguments and returns a UrlMatchResult object.

  • segment :URL 段的陣列。

    segments : An array of URL segments.

  • group :段組。

    group : A segment group.

  • route :要匹配的路由。

    route : The route to match against.

下列例子中實現的匹配器會匹配 HTML 檔案。

The following example implementation 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 }];