Implement catch-all routes for dynamic routes? (Example inside) #571
daveschumaker
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
For info, there are some use cases that I don't think they have a workaround. For instance when you don't have control for the tree (really dynamic routes, where also the nesting is dynamic) So It's not only about capturing / and /book in the same file, but |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello! Thanks for the hard work you've been doing on Fresh. It's pretty nice to use!
I'm looking at the docs for setting up dynamic routes, I have the following structure in my project:
So, landing on
/books
will load the index component, and/books/2
will load a component to render anything related to that specific page. The issue is that bothindex.tsx
and[page.tsx]
are essentially duplicating logic. As far as I can tell, there isn't a way to create a dynamic catch all route (e.g., a route that will work for/books, /books/1 (potentially redirected to /books), /books/2, /books/174, etc
).Looking at some other frameworks, Next.js has an interesting way of handling this. They use double brackets for a catch all route:
Anyway, I'd like to throw this idea into the ring for a future version of Fresh. I think it'd be pretty nice to have! 🙏
EDIT:
For now, I just modified
/routes/_middleware.ts
to forward anything without a page number (...I dislike having a URL to page 1, but it's workable at least):Beta Was this translation helpful? Give feedback.
All reactions