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

View File

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

View File

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