Skip to content

How to specify search results for specific routes? #1229

Answered by KamilDev
KamilDev asked this question in Q&A
Discussion options

You must be logged in to vote

Is this a good approach?

'use client';

import { usePathname } from 'next/navigation';
import { RootProvider } from 'fumadocs-ui/provider';
import { PropsWithChildren } from 'react';

export function SearchProvider({ children }: PropsWithChildren) {
  const pathname = usePathname() ?? '';
  const api = pathname.startsWith('/docs')
    ? '/api/search/docs'
    : pathname.startsWith('/blog')
      ? '/api/search/blog'
      : '/api/search';

  return (
    <RootProvider
      search={{
        options: {
          api
        }
      }}
    >
      {children}
    </RootProvider>
  );
}

By the way, is the RootProvider search option api field in the documentation? I could not find it when loo…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@KamilDev
Comment options

@fuma-nama
Comment options

@KamilDev
Comment options

Answer selected by KamilDev
@fuma-nama
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants