UNPKG

route-path-match

Version:

compile route path template, match route path params

34 lines (27 loc) 1.11 kB
/** 匹配规则 - 通配符: - 匿名通配符: * 与 ** 前者匹配除/之外的字符,后者匹配任意字符,可以通过 *<\\d+> 的形式自定义正则 - 变量通配符: :id 与 ::id 含义和用法同匿名通配符,可以通过 :id<\\d+> 的形式自定义正则 - 变量名:只支持使用驼峰形式,形如 :groupId - 适配正则: - 继承正则: ( ) 与 ? 等3个字符为正则的含义及用法,即分组与可选 - 自定义通配符正则: id<[0-9]+|all> 其中 < > 字符会被替换为 ( ) 其中包裹的内容会被识别为该变量的正则表达式。其中的反斜杠需要转义,如 \\d+ 使用示例 - /assets/** - /assets/::path - /shop-*-assets/*.js - /shop-:part-assets/:file.js - /:lang/:group/:gid - (/:lang)?/:group(/:gid)? - (/:lang)?/:group/:gid(:ext<\\.(js|json)>)? */ export type RouteParams = { [key: string]: any; }; export type PathMatcher = RegExp | string; export type parsePathTpl = (pathTpl: string) => PathMatcher; export type matchPathParams = ( pathMatcher: PathMatcher, path: string ) => RouteParams | void;