Configure `basePath` for `<Link />` components
mainWhen a <Link /> is used within a router context (i.e., inside a component tree provided by useRoutes), it automatically inherits the basePath defined in the useRoutes configuration.
If you need to change the base path for a specific link, you can provide a basePath prop directly to the <Link />, which will override the inherited value. The basePath is prepended to the href value.
import { useRoutes, Link } from 'raviger'
function Home () {
return (
<div>
{/* If useRoutes has basePath: 'app', this resolves to /app/foo */}
<Link href="/foo" />
{/* This overrides the inherited path and resolves to /bar/foo */}
<Link href="/foo" basePath="/bar" />
</div>
)
}
const routes = {
'/': () => <Home />
}
export default function App() {
return useRoutes(routes, { basePath: 'app' })
}