/
githubmirror
/
ionic
Обзор
Документация
Войти
/
githubmirror
/
ionic
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/react-router/src/ReactRouter/utils/matchPath.ts
47 строк
1 KB
Sean Perkins
fix(react): router creates new view instances of parameterized routes (#28616)
02 дек 2023, 01:11
Не верифицирован
02 дек 2023, 01:11
1705d06
Код
Авторство
О чём код?
import { matchPath as reactRouterMatchPath } from 'react-router'; interface MatchPathOptions { /** * The pathname to match against. */ pathname: string; /** * The props to match against, they are identical to the matching props `Route` accepts. */ componentProps: { path?: string; from?: string; component?: any; exact?: boolean; }; } /** * @see https://v5.reactrouter.com/web/api/matchPath */ export const matchPath = ({ pathname, componentProps, }: MatchPathOptions): false | ReturnType<typeof reactRouterMatchPath> => { const { exact, component } = componentProps; const path = componentProps.path || componentProps.from; /*** * The props to match against, they are identical * to the matching props `Route` accepts. It could also be a string * or an array of strings as shortcut for `{ path }`. */ const matchProps = { exact, path, component, }; const match = reactRouterMatchPath(pathname, matchProps); if (!match) { return false; } return match; };