react-router-dom#matchRoutes JavaScript Examples

The following examples show how to use react-router-dom#matchRoutes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.js    From vitedge with MIT License 7 votes vote down vote up
export function resolvePropsRoute(routes, path, base) {
  const url = createUrl(path)
  url.pathname = withoutPrefix(url.pathname, PROPS_PREFIX + '/')

  const routeBase = base && withoutSuffix(base({ url }), '/')
  const fullPath = getFullPath(url, routeBase)

  const [{ route, params = {} } = {}] = matchRoutes(
    routes,
    createUrl(fullPath).pathname
  )

  const data = {
    ...route,
    fullPath,
    query: Object.fromEntries(url.searchParams),
    params,
  }

  return buildPropsRoute(data)
}