svobik7 / next-roots

Next.js utility to generate i18n routes in the new APP directory.
https://next-roots-svobik7.vercel.app/
MIT License
178 stars 12 forks source link

fix(router): fix the sort function of the router #257

Closed zto-sbenning closed 1 month ago

zto-sbenning commented 1 month ago

The router has an issue where it fails to prioritize dynamic segment over catchAll ones. We now create a route-weight map on router creation. This map is used by the sorting function to prioritize static > dynamic > catchAll

fix #248

Note: A test is added for the previous failing case in src/router/router.test.ts

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-roots-wcmb ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2024 11:00am
svobik7 commented 1 month ago

Hi @zto-sbenning,

thank you for your initial implementation. Good job 👍

As sorting mechanism is not trivial now it makes sense to do the sorting only once (in router constructor). Also second thought on my initial naming idea called "route weight" brought me to the conclusion that "route priority" would be more clear.

To make it smoother I pushed my own commit where I address that. What I did:

  1. Extracted schema and route utils to separate files
  2. Added tests for those new utils files
  3. Moved routes sorting to router constructor so that it is done just once

Could you please check my commit if makes sense to you https://github.com/svobik7/next-roots/pull/257/commits/3a164157137dc0b7c51fb8412a09e1e8fbf2b15c?

github-actions[bot] commented 1 month ago

:tada: This issue has been resolved in version 3.10.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: