-
Notifications
You must be signed in to change notification settings - Fork 2.6k
perf: Router jump #3783
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
perf: Router jump #3783
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -281,7 +281,6 @@ const currentPermissionKey = computed(() => { | |
| return route.meta?.resourceType as string | ||
| }) | ||
|
|
||
|
|
||
| const resource = reactive({ | ||
| resource_id: route.params.id as string, | ||
| resource_type: route.meta.resourceType as string, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet is essentially correct as it stands, but there are a few minor improvements that could be made:
Here's a slightly refined version of the code: const currentPermissionKey = computed(() => {
return (route.meta as { resourceType?: string })?.resourceType as string || ''
})
// Ensure route exists before using params.id
if (typeof router.currentRoute.value !== 'undefined') {
const resourceId = router.currentRoute.value.params.id as string
// Use currentLocation instead of meta again if needed
const locationId = route.params.locationId || ''
const resourceInfo = {
resourceId: resourceId,
permissionKey: currentPermissionKey.value,
locationId: locationId, // Adjust this based on your actual use case
}
} else {
console.warn('No active route found.');
}Key Changes:
These changes make the code cleaner and more readable while maintaining its functionality. Make sure to adjust any parts where additional logic or context information is required for your specific application. |
||
|
|
||
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.
The current code checks the
toroute parameters to determine whether an access permission is required based on the route configuration provided in theroutesarray. There are no apparent errors, but there are some optimizations and enhancements that can be made:Optimizations
Early Return: Instead of repeatedly checking conditions after finding routes, return early when a match is found:
Simplify Function Calls: Use arrow functions instead of named function calls where applicable for better performance.
Reduce Code Duplication: Remove redundant logic blocks by consolidating them into functions with appropriate names like
findAccessibleRoute.Potential Enhancements
Dynamic Routing Configuration: If the routing configuration changes frequently or depends on external dependencies, consider making it reactive using frameworks features like Vue’s composition API or Vuex.
Error Handling: Add error handling to handle unexpected cases, such as non-object data types or missing properties.
Here’s how you might structure the optimized version:
These optimizations aim to make the code more concise, efficient, and easier to maintain. Adjust the implementation details according to your application's specific requirements and architecture.