Returns the basePath string you configured in withSlugtree. All href values on nodes are already prefixed with this path.

import { getBasePath } from 'slugtree'

const basePath = getBasePath()
// e.g. '/docs'

Return value

Returns string. Defaults to '/' unless overridden in plugin/integration options.

Usage

Use it to build links or redirects without hardcoding the path in your components:

import { getBasePath } from 'slugtree'
import { redirect } from 'next/navigation'

export default function RootPage() {
  redirect(getBasePath())
}

For client components, use useBasePath() from slugtree/react.