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

Custom router gets stuck in a SetRoute loop on first navigation #151

Closed
NickDarvey opened this issue May 27, 2020 · 2 comments
Closed

Custom router gets stuck in a SetRoute loop on first navigation #151

NickDarvey opened this issue May 27, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@NickDarvey
Copy link

I'm having an issue with implementing a custom router where it setRoute is called infinitely.

let router : Router<Page, Model, Message> = {
  getEndPoint = fun m -> m.page
  setRoute = fun path ->
      match path.Trim('/').Split('/') with
      | [||]     -> Some <| Home
      | [|"c" |] -> Some <| Counter
      | _ -> None
      |> Option.map SetPage
  getRoute = function
      | Page.Home    -> "/"
      | Page.Counter -> "/c"
}

https://github.com/NickDarvey/bolero-custom-router/blob/0bfea305481d412cc4ab9f2ae25e2bd85f8c8c49/src/RoutingPlz.Client/Main.fs#L98-L111

Repro

  1. Clone this repo
  2. Run app
  3. Click 'counter' link

Expected

Navigates to counter page via an invocation of setRoute.

Actual

setRoute is called infinitely.

System info

  • The repro project a stripped down version of the bolero-app template.
  • I (believe I) followed the steps in the docs to create my router.

This is at the top of the call stack:

Bolero.dll!<StartupCode$Bolero>.$Components.OnLocationChanged@146<RoutingPlz.Client.Main.Model, RoutingPlz.Client.Main.Message>.Invoke(Bolero.IRouter<RoutingPlz.Client.Main.Model, RoutingPlz.Client.Main.Message> router)

member private this.OnLocationChanged (_: obj) (e: LocationChangedEventArgs) =
this.Router |> Option.iter (fun router ->
let uri = this.NavigationManager.ToBaseRelativePath(e.Location)
let route = router.SetRoute uri
Option.iter dispatch route)

@NickDarvey NickDarvey changed the title Custom router gets stuck in a SetLocation loop after first SetPage Custom router gets stuck in a SetRoute loop on first navigation May 27, 2020
@Tarmil Tarmil added the bug Something isn't working label May 27, 2020
@Tarmil
Copy link
Member

Tarmil commented Jun 1, 2020

Ah, I found the problem. In the custom router, getRoute actually needs to return relative paths, ie without the initial /. That's doubly wrong: it's not intuitive, and it contradicts the documentation! I'll fix it so that either absolute or relative paths can be used.

@Tarmil Tarmil closed this as completed in e41469e Jun 1, 2020
@NickDarvey
Copy link
Author

Fantastic, thank you @Tarmil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants