1234567891011121314151617181920 |
- export const fillRoutePath = <T extends string>(path: T, params: ExtractRouteParams<T>) => {
- let processPath: string = path
- for (const [key, value] of Object.entries(params)) {
- const rg = new RegExp(`:${key}`)
- processPath = processPath.replace(rg, value as string)
- }
- return processPath
- }
- const place = /(?:\/:([^/]*))/g
- export const verifiRoutePath = (pathname: string, path: string) => {
- const rg = path
- .replace(/\/([^:])/g, (_, d) => `\\/${d}`)
- .replace(place, () => `(?:/([^/]*))`)
- return new RegExp(`^${rg}$`).exec(pathname)
- }
|