stackflow icon indicating copy to clipboard operation
stackflow copied to clipboard

feat(history-sync): add `priority` option to routes

Open XiNiHa opened this issue 1 year ago • 6 comments

Please check the added test suite to see the expected behavior!

XiNiHa avatar Nov 16 '24 06:11 XiNiHa

🦋 Changeset detected

Latest commit: 916185d4d97c2cf283a8764d6f6ac428fa54460c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@stackflow/plugin-history-sync Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Nov 16 '24 06:11 changeset-bot[bot]

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

Name Status Preview Updated (UTC)
stackflow-docs ✅ Ready (Inspect) Visit Preview Nov 16, 2024 6:17am

vercel[bot] avatar Nov 16 '24 06:11 vercel[bot]

Our team has been thinking about this issue before, and we thought of several candidates for the acceptable priority rule.

  1. Users set their own path priorities (This PR's way)
  2. Indirect reflection in the order of declaration (vue router)
  3. Score calculation (react router, current way)

Which method do you think is the best?

orionmiz avatar Dec 10 '24 08:12 orionmiz

Although I also believe that the score calculation should be the default behavior in most cases, I found that it sometimes makes sense to override this and therefore made this PR, which works as a hybrid of 1 and 3. I prefer my solution the most since it provides both a good default and an escape hatch that can be utilized in advanced use cases.

XiNiHa avatar Dec 10 '24 08:12 XiNiHa

Although I also believe that the score calculation should be the default behavior in most cases, I found that it sometimes makes sense to override this and therefore made this PR, which works as a hybrid of 1 and 3. I prefer my solution the most since it provides both a good default and an escape hatch that can be utilized in advanced use cases.

Oh, I see. Is there an example that requires an escape hatch against score rule?

orionmiz avatar Dec 10 '24 09:12 orionmiz

My use case was dynamically matching splat routes in runtime and falling back to the default route-matching algorithm when no match was found. It was for keeping the URLs simple while using https://github.com/contentstech-com/stackflow-plugin-omniflow and also utilized #535 to appropriately transform activity params to a URL. I can also share a code snippet for dynamic route matching if you need to see that.

XiNiHa avatar Dec 10 '24 17:12 XiNiHa