fix: Nested Folders Feature Routing (#677)

This commit is contained in:
Jonas Zeiger 2023-03-31 04:59:38 +02:00 committed by GitHub
parent 6ae948dabe
commit c4ac63a0e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View File

@ -76,8 +76,8 @@ function CollectionSearchRedirect() {
}
function EditEntityRedirect() {
const { name, entryName } = useParams();
return <Navigate to={`/collections/${name}/entries/${entryName}`} />;
const params = useParams();
return <Navigate to={`/collections/${params.name}/entries/${params['*']}`} />;
}
const App = ({
@ -199,7 +199,7 @@ const App = ({
element={<EditorRoute collections={collections} newRecord />}
/>
<Route
path="/collections/:name/entries/:slug"
path="/collections/:name/entries/*"
element={<EditorRoute collections={collections} />}
/>
<Route
@ -209,14 +209,14 @@ const App = ({
}
/>
<Route
path="/collections/:name/filter/:filterTerm"
path="/collections/:name/filter/*"
element={<CollectionRoute collections={collections} />}
/>
<Route
path="/search/:searchTerm"
element={<CollectionRoute collections={collections} isSearchResults />}
/>
<Route path="/edit/:name/:entryName" element={<EditEntityRedirect />} />
<Route path="/edit/:name/*" element={<EditEntityRedirect />} />
<Route path="/page/:id" element={<Page />} />
<Route element={<NotFoundPage />} />
</Routes>

View File

@ -18,7 +18,9 @@ const CollectionRoute = ({
isSingleSearchResult,
collections,
}: CollectionRouteProps) => {
const { name, searchTerm, filterTerm } = useParams();
const params = useParams();
const { name, searchTerm } = params;
const filterTerm = params['*'];
const collection = useMemo(() => {
if (!name) {
return false;

View File

@ -12,7 +12,9 @@ interface EditorRouteProps {
}
const EditorRoute = ({ newRecord = false, collections }: EditorRouteProps) => {
const { name, slug } = useParams();
const params = useParams();
const name = params.name;
const slug = params['*'];
const shouldRedirect = useMemo(() => {
if (!name) {
return false;