Ability to rewrite as part of middleware logic #237
Replies: 3 comments 2 replies
-
Nice idea, more generally there could be a canonical and a display URL. Every time the url changes it is passed to a canonicalization function (must work on the client too? Or contact server every time?) , and then to a display function to set the URL in the browser or to redirect the SSR. Routing is done with the canon url. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the qwik response :) FYI - The below almost fully works,
Regarding your suggestion about canonical and display-name URLs - I think there might be an opportunity for even greater flexibility. Rather than specifically adding display-name functionality to routes, what if we had a more general rewrite mechanism that allows rendering any application route under any URL path we choose (agnostically) Let me know what you think 🙏 |
Beta Was this translation helpful? Give feedback.
-
@omerman I don't understand your last comment, can you give an example? |
Beta Was this translation helpful? Give feedback.
-
What's the motivation for this proposal?
Sometimes the url should include more info, but the actual dir-path would ideally be just an identifier. for example:
We want our url to be informative for SEO reasons.
And have our directory based routing be clear and id driven:
So for example:
https://my.example.articles.com/qwik-is-a-great-platform
---> rewrite ----->
https://my.example.articles.com/7777
What do you think?
Proposed Solution / Feature
What do you propose?
First of all I want you to know that I partially managed to do it, it's just not working great:
I performed the above as a test, but if the code uses useLocation() to build any links,it easily breaks, because the router
thinks it's at /track/chords/4983 even-though its not.
Code examples
I was thinking, like
redirect
, we could have,.rewrite
Ideally My test above would look like this:
Links / References
This feature exists in nextjs middlewares, you are able to return Rewrite.
This is something I used to do:
Beta Was this translation helpful? Give feedback.
All reactions