pacocoursey / cmdk

Fast, unstyled command menu React component.
https://cmdk.paco.me
MIT License
9.68k stars 279 forks source link

discussion: better way for 'routing' #132

Open ZhangHanwen96 opened 1 year ago

ZhangHanwen96 commented 1 year ago

I am just curious, and want to find a better way for routing, navigating between pages.

the example navigates on top level element:

activePage === 'xxx' && <Component1 />
activePage === 'xxxx' && <Component2 />
activePage === 'xxxxx' && <Component2 />

But as the command list grows bigger and nested command is used frequently, e.g.: 'home > projects > :projectID'

Does someone has a nicer way of doing this?

My solution with react-router-6

 <Routes location={`/<current-path>${location}`}> // "current-path refers to the path of the component that contains the current component as a child."
            <Route path="/home">
              <Route index element={<Home setPage={setPage} />}></Route>
              <Route path="prompts">
                <Route index element={<Prompts setPage={setPage} />}></Route>
                <Route path=":type" element={<div>type</div>}></Route>
              </Route>
              <Route path="projects" element={<Projects2 />} />
            </Route>
</Routes>
joaom00 commented 1 year ago

Hey @ZhangHanwen96, I made a small API to work with pages and breadcrumbs in cmdk. Hope it helps