directory based conditional routing #235
SKhajeh
started this conversation in
Proposals For Qwik
Replies: 1 comment 4 replies
-
|
hmm I'm not convinced. To know how a request will match you have to read all the files. The total amount of code is more because of extra boilerplate. Also, all these file patterns are not very discoverable, you have to know about them in order to use them. And a nitpick, directories starting with a dot are hidden by default. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What is it about?
transfer the database-stored-state oriented conditionals from rendering level to the routing level
What's the motivation for this proposal?
Problems you are trying to solve:
Currently:
User navigates to this url:
example.com/users/12312
this url hits this pattern:
example.com/users/[uid]
the corresponding index.tsx file(API endpoints etc.) is executed, and the reasoning(the if-else statements) about whether the user should receive a viewers or account owners rendering of that page is performed inside the components function. This makes the index.tsx (etc) file crowded, because it has to handle both of the situations in the same file which I guess its opposing to the principle of separation of concerns.
Goals you are trying to achieve:
Any other context or information you want to share:
In addition, it's a cool idea, 😄.
Proposed Solution / Feature
What do you propose?
Instead:
User navigates to this url:
example.com/users/12312
this url hits one of these patterns:
example.com/users/[uid].logged-in
eaxmple.com/users/[uid]
Code examples
there is a file "/src/routes/users/[uid].logged-in/logged-in.ts" which looks like this:
if a NavigateFalse object is returned by the logged-in.ts file, the routing system passes to the next matched pattern and continues until it either receives a NavigateTrue return object or it runs out of "/src/routes/users/[uid].*" matched patterns and then it renders the file "/src/routes/users/[uid]/index.tsx".
Otherwise, it goes to the corresponding index file located inside of the directory for the matched conditional route, i.e. "/src/routes/users/[uid].logged-in/index.tsx
Additionally:
"/src/routes/products/[pid].in-stock.sales-active"
and the corresponding route folder structure might look this way:
Thanks for reviewing this idea, 🙏.
Beta Was this translation helpful? Give feedback.
All reactions