Skip to content
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

Cannot mix static and dynamic routes even if conditional #1080

Open
steinybot opened this issue Dec 19, 2022 · 0 comments
Open

Cannot mix static and dynamic routes even if conditional #1080

steinybot opened this issue Dec 19, 2022 · 0 comments

Comments

@steinybot
Copy link

I was expecting something like this to work:

    val id = dsl.string("[^/]+")

    (emptyRule
      | staticRoute("products", Products) ~> render(<.div("Products"))
      | (staticRoute("products" / "add", AddProduct) ~> render(<.div("Add Product"))).addCondition(CallbackTo(true))
      | dynamicRouteCT("products" / id.caseClass[ProductInfo]) ~> dynRender((info: ProductInfo) => <.div(s"Product ${info.id}"))
      ).notFound(redirectToPage(AddProduct)(HistoryReplace))

But going to products/add fails with:

RoutingRulesF.scala:85 Uncaught japgolly.scalajs.react.extra.router.RoutingRulesF$Exception: Multiple (2) (unconditional) routes specified for path products/add
    at http://localhost:8081/bug-reports-fastopt-bundle.js:3092:11
    at $c_sjsr_AnonFunction0.apply__O (http://localhost:8081/bug-reports-fastopt-bundle.js:10644:43)
    at $c_Ljapgolly_scalajs_react_callback_Trampoline$.run__Ljapgolly_scalajs_react_callback_Trampoline__O (http://localhost:8081/bug-reports-fastopt-bundle.js:1693:158)
    at http://localhost:8081/bug-reports-fastopt-bundle.js:1860:62
    at $c_sjsr_AnonFunction0.apply__O (http://localhost:8081/bug-reports-fastopt-bundle.js:10644:43)
    at __webpack_modules__../bug-reports-fastopt.js.$c_Ljapgolly_scalajs_react_component_builder_ComponentBuilder$Step1$.initialState$extension__T__F0__Ljapgolly_scalajs_react_component_builder_ComponentBuilder$Step2 (http://localhost:8081/bug-reports-fastopt-bundle.js:1851:19)
    at $c_sjsr_AnonFunction1.apply__O__O (http://localhost:8081/bug-reports-fastopt-bundle.js:10668:43)
    at $c_Ljapgolly_scalajs_react_component_builder_ViaReactComponent$.japgolly$scalajs$react$component$builder$ViaReactComponent$$$anonfun$apply$2__Ljapgolly_scalajs_react_facade_React$Component__Ljapgolly_scalajs_react_internal_Box__sr_ObjectRef__F1__F1__Ljapgolly_scalajs_react_facade_React$Component (http://localhost:8081/bug-reports-fastopt-bundle.js:2244:31)
    at new <anonymous> (http://localhost:8081/bug-reports-fastopt-bundle.js:2080:78)
    at constructClassInstance (http://localhost:8081/bug-reports-fastopt-bundle.js:38596:18)

Ideally it would be without the condition as that was my attempt to trigger the rule that says "conditional routes are selected over unconditional routes" but that makes no difference.

It seems that this was unexpectedly encountered by others in the past after a new release: https://gitter.im/japgolly/scalajs-react?at=5e2ef481da04a624f49145d5

prepareParseFn in japgolly.scalajs.react.extra.router.RoutingRulesF only ever seems to return a static route no matter if it was created by dynamicRoute or not.

Reproduction: https://github.com/steinybot/bug-reports/tree/scalajs-react/static-and-dynamic-route

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant