From 0b618923d48a5ac97060a357efc136ec5680371f Mon Sep 17 00:00:00 2001 From: Ryan Haskell Date: Sun, 21 Apr 2024 09:09:34 -0500 Subject: [PATCH] Update route-path.md --- docs/reference/route-path.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/reference/route-path.md b/docs/reference/route-path.md index 196313ad..b79fb8d2 100644 --- a/docs/reference/route-path.md +++ b/docs/reference/route-path.md @@ -61,4 +61,33 @@ This can also be helpful when working with Elm UI, Elm CSS, or anything that isn Route.toString : Path -> String ``` -__Note:__ The resulting URL string does __not contain__ query parameters or hash fragments (see [Route.toString](./route.md) if you need those) \ No newline at end of file +__Note:__ The resulting URL string does __not contain__ query parameters or hash fragments (see [Route.toString](./route.md) if you need those) + +## Route.Path.fromString + +When using programmatic navigation with `Effect.pushRoute` or `Effect.replaceRoute`, you might need to go from a raw URL path like `"/blog"` to an Elm Land route path like `Route.Path.Blog`. + +For that reason, Elm Land also exposes a `fromString` function. + +```elm +Route.fromString : String -> Maybe Path +``` + +#### Example usage + +```elm +update : Route () -> Msg -> Model -> ( Model, Effect Msg ) +update route msg model = + case msg of + OnSignInSuccess user -> + ( { model | user = Just user } + , Effect.pushRoute + { path = + Dict.get "from" route.query + |> Maybe.andThen Route.Path.fromString + |> Maybe.withDefault Route.Path.Dashboard + , query = Dict.empty + , hash = Nothing + } + ) +```