Skip to content

Commit

Permalink
Update route-path.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-haskell committed Apr 21, 2024
1 parent 67489e3 commit 0b61892
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion docs/reference/route-path.md
Expand Up @@ -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)
__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
}
)
```

0 comments on commit 0b61892

Please sign in to comment.