-
Notifications
You must be signed in to change notification settings - Fork 232
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: add utility for router params (#120) #158
Conversation
export function getRouterParams (event: CompatibilityEvent): CompatibilityEvent['context'] { | ||
// Fallback object needs to be returned in case router is not used (#149) | ||
return event.context.params || {} | ||
} |
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.
This comment is just for GitHub to add a reference link to #149.
Codecov Report
@@ Coverage Diff @@
## main #158 +/- ##
==========================================
- Coverage 65.53% 65.40% -0.14%
==========================================
Files 14 14
Lines 911 922 +11
Branches 195 200 +5
==========================================
+ Hits 597 603 +6
Misses 124 124
- Partials 190 195 +5
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@@ -10,6 +10,14 @@ export function getQuery (event: CompatibilityEvent) { | |||
/** @deprecated Use `h3.getQuery` */ | |||
export const useQuery = getQuery | |||
|
|||
export function getRouterParams (event: CompatibilityEvent): CompatibilityEvent['context'] { |
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.
Can we please export it from src/router.ts
or src/utils/router.ts
?
test/utils.test.ts
Outdated
@@ -53,6 +53,56 @@ describe('', () => { | |||
}) | |||
}) | |||
|
|||
describe('getRouterParams', () => { |
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.
Can we please move it to test/router.test.ts
?
Nice addition! Would be nice to also introduce |
I added |
src/utils/request.ts
Outdated
} | ||
|
||
/** @deprecated Use `h3.getRouterParam` */ | ||
export const useRouterParam = getRouterParam |
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.
We never introduce useRouter*
utils. Then don't need to add and deprecate. deprecation of other utils was that they could be used in existing projects.
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.
Deleted! 🙋♀️
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.
Amazing! Thank you!
Resolves #120
I added
getRouterParams(event)
utility function.I also added
useRouterParams(event)
for it to be aligned with other API until the next braking change (may be v1?).