-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(builder): support async extendRoutes
#7754
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #7754 +/- ##
=======================================
Coverage 68.83% 68.83%
=======================================
Files 90 90
Lines 3821 3821
Branches 1034 1034
=======================================
Hits 2630 2630
Misses 968 968
Partials 223 223
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Can this idea be even considered good or the whole thing should be scraped? Thanks for insights. btw: |
Current behaviour its impossible to extend routes with APIs Expected behaviour Being able to await requests to server that are required for extendingRoutes With this simple change, we are able to extend our nuxt router with async data without need to create custom router.
packages/builder/src/builder.js
Outdated
@@ -420,7 +420,7 @@ export default class Builder { | |||
) | |||
// Only overwrite routes when something is returned for backwards compatibility | |||
if (extendedRoutes !== undefined) { | |||
templateVars.router.routes = extendedRoutes | |||
templateVars.router.routes = await extendedRoutes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think would be better to put await here because result of the promise can be undefined too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved
extendRoutes
Thank you for the merge, i'd like to extend Routes as well after fetching data form an API, but during runtime. the scenario is the following:
i am now having one dynamic route that checks the requested route and shoves it into a dynamic component, but somehow it feels wrong to do it that way 🤮 any help would be appreciated |
Hey @gianpesto maybe opening a dicsussion with more details how are you currently doing stuff? :) |
Current behaviour
its impossible to extend routes with APIs
Expected behaviour
Being able to await requests to server that are required for extendingRoutes
Types of changes
Description
With this simple change, we are able to extend our nuxt router with async data without need to create custom router.
In documentation is something like this:
But we might need something like this:
Checklist: