Refactor routing functions to work without context #121
Replies: 4 comments 4 replies
-
Hi @nelsonprsousa, Thanks for your detailed description. Point 2. Thanks for sharing your solution. But I would avoid bringing it into the documentation: I think that for a library it is better to offer the tools, and then let each developer do their own implementation according to the requirements. Otherwise the documentation becomes difficult to maintain. Just as a side note, also keep in mind that redirects within an Point 1. The problem exists, you are right, but it exists only the first time the app starts. Then the shared context (such as the
|
Beta Was this translation helpful? Give feedback.
-
Point 2. Totally get it. No worries. Would you please let me know what do you mean by route guards? Point 1. Just letting you know that the first bullet is also a breaking change since |
Beta Was this translation helpful? Give feedback.
-
Also, let me ask you if we can add the default lang to the |
Beta Was this translation helpful? Give feedback.
-
Added setSpeakContext function to share the config server side. There is no need to refactor the functions. See https://github.com/robisim74/qwik-speak/blob/main/docs/tutorial-routing-rewrite.md#routing ((with also indications of how to handle errors and redirects) Greetings |
Beta Was this translation helpful? Give feedback.
-
Hi 👋 First of all thank you for your hard work towards this library. Awesome job! 👏
What I am bringing to discussion
I'd like to bring to discussion the refactor of routing functions, particularly
translatePath
(but others likelocalizePath
could also benefit from it, even though I am not using it).Current use cases where these functions do not work and could work
In the
plugin.ts
(or[email protected]
) it could be valid to usetranslatePath
, in order to perform redirects. For example, in my case, I do not have a "languageless" valid route. This means thatexample.com/
will redirect to, for example,example.com/en/
ifen
is the default language. Or, if the user changed the language to, let's say,fr
, then we are saving alang
cookie to persist this preference. The goal it that when the user visits the site again throughexample.com/*
, he will be redirected toexample.com/cookiePreference/*
.AFAIK, and because these functions needs context, they will not properly work in the middleware.
Possible API
Based on my research on
translatePath
function, it is now using SpeakContext to get the rewriteRoutes and the current language. A possible API to remove the need of a context would be to pass therewriteRoutes
object and to make lang mandatory instead of optional.Function used on my project as a workaround
Please note that I removed some code that is necessary for qwik-speak library ecosystem but not for my current project.
Click me
[email protected]
if it also makes sense to add to this library to help others getting the same behaviourClick me
Let me know:
Beta Was this translation helpful? Give feedback.
All reactions