Skip to content

Commit

Permalink
fix(proejects): use other methods to replace toSorted for better comp…
Browse files Browse the repository at this point in the history
…atibility with more browsers
  • Loading branch information
mufeng889 committed Aug 14, 2024
1 parent 5afba5e commit 5bc13d6
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/store/slice/route/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ function filterAuthRouteByRoles(route: ElegantConstRoute, roles: string[]) {
function sortRouteByOrder(route: ElegantConstRoute) {
const sortedRoute = { ...route };
if (sortedRoute.children?.length) {
sortedRoute.children = sortedRoute.children.toSorted(
(next, prev) => (Number(next.meta?.order) || 0) - (Number(prev.meta?.order) || 0)
);

sortedRoute.children = sortedRoute.children.map(sortRouteByOrder);
sortedRoute.children = sortedRoute.children
.map(sortRouteByOrder)
.sort((a, b) => (Number(a.meta?.order) || 0) - (Number(b.meta?.order) || 0));
}

return sortedRoute;
Expand All @@ -58,9 +56,5 @@ function sortRouteByOrder(route: ElegantConstRoute) {
* @param routes routes
*/
export function sortRoutesByOrder(routes: ElegantConstRoute[]) {
let sortedRoutes = routes.toSorted((next, prev) => (Number(next.meta?.order) || 0) - (Number(prev.meta?.order) || 0));

sortedRoutes = sortedRoutes.map(sortRouteByOrder);

return sortedRoutes;
return routes.map(sortRouteByOrder).sort((a, b) => (Number(a.meta?.order) || 0) - (Number(b.meta?.order) || 0));
}

0 comments on commit 5bc13d6

Please sign in to comment.