@jsbit/find-matching-route

0.0.4 • Public • Published

findMatchingRoute

findMatchingRoute(routes, currentPath) => object | null

  • Function for finding a route definition based on some path
  • Useful for building your own spa router.
  • A building block for @jsbit/spa-router.
  • Supports nested routes (as deeply as you need)
  • Not coupled to any rendering framework like React or Preact
const onboardingRoutes = {
  landing: {path: '/landing', component: Landing},
  login: {path: '/login', component: Login}
}

const mainRoutes = {
  profile: {path: '/profile/:profileId', component: Profile},
  onboarding: {routes: onboardingRoutes, component: OnboardingApp}
}

findMatchingRoute(mainRoutes, "/profile/123?query=example")
> {
  component: OnboardingApp,
  args: {profileId: 123, query: 'example'},
  definition: {path: '/profile/:profileId', component: Profile, name: 'onboarding'}
}

findMatchingRoute(mainRoutes, "/owls")
> null

/@jsbit/find-matching-route/

    Package Sidebar

    Install

    npm i @jsbit/find-matching-route

    Weekly Downloads

    0

    Version

    0.0.4

    License

    ISC

    Unpacked Size

    10.3 kB

    Total Files

    6

    Last publish

    Collaborators

    • adriaanwm