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

Add Router.withNotFound to handle unknown URL #320

Merged
merged 4 commits into from
Aug 24, 2023
Merged

Add Router.withNotFound to handle unknown URL #320

merged 4 commits into from
Aug 24, 2023

Conversation

Tarmil
Copy link
Member

@Tarmil Tarmil commented Aug 22, 2023

Fixes #308.

Example use:

type Page =
    | [<EndPoint "/">] Home
    | [<EndPoint "/not-found">] NotFound

type Model =
    { page: Page }

type Message =
    | PageChanged of Page

let router =
    Router.infer PageChanged (fun m -> m.page)
    |> Router.withNotFound NotFound

This will send the message PageChanged NotFound

  • during initialization (before first display) if the URL couldn't be parsed;
  • after the URL was programmatically set to a value that can't be parsed.

It does not change the behavior when the user clicks a link to a URL that can't be parsed: these are considered external links, and standard navigation is performed.

Breaking changes

  • The interface IRouter<'model, 'msg> has an additional property NotFound: 'msg option.
  • The record Router<'endpoint, 'model, 'msg> has
    • additional field makeMessage: 'endpoint -> 'msg;
    • additional field notFound: 'endpoint option;
    • type of field setRoute has changed to string -> 'endpoint option instead of string -> 'msg option.

These should be transparent for most users.

@Tarmil Tarmil self-assigned this Aug 22, 2023
@Tarmil Tarmil merged commit 24ba13c into master Aug 24, 2023
7 checks passed
@Tarmil Tarmil deleted the notfound branch August 24, 2023 14:48
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

Successfully merging this pull request may close these issues.

[Router] Support a not found route value or page DU value when no route matched
1 participant