Skip to main content Link Menu Expand (external link) Document Search Copy Copied

useBasePath

Get the basePath set by a parent useRoutes component (empty string if none)

API

export function useBasePath(): string

Basic

import { useRoutes, useBasePath } from 'raviger'

function Home () {
  let basePath = useBasePath()
  // Will be 'app' when render by the parent below
  return <span>{basePath}</span>
}

const routes = {
  '/': () => <Home />
}

export default function App() {
  return useRoutes(routes, { basePath: 'app' })
  )
}