Skip to content

Commit

Permalink
Add HistoryMode overloads for navigation, fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid-Ajaj committed Aug 19, 2019
1 parent 492562d commit 8933c81
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 65 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -124,7 +124,7 @@ Aside from listening to manual changes made to the URL by hand, the `Router.rout

The function `Router.navigate` has the general syntax:
```
Router.navigate(segment1, segment2, ..., segmentN, [query string parameters])
Router.navigate(segment1, segment2, ..., segmentN, [query string parameters], [historyMode])
```
Examples of the generated paths:
```fs
Expand All @@ -139,6 +139,10 @@ Router.navigate("users", [ "id", 1 ]) => "#/user?id=1"
Router.navigate("users", [ "name", "john"; "married", "false" ]) => "#/users?name=john&married=fase"
// paramters are encoded automatically
Router.navigate("search", [ "q", "whats up" ]) => @"#/search?q=whats%20up"
// Pushing a new history entry is the default bevahiour
Router.navigate("users", HistoryMode.PushState)
// to replace current history entry, use HistoryMode.ReplaceState
Router.navigate("users", HistoryMode.ReplaceState)
```

Here is a full example in an Elmish program.
Expand Down
2 changes: 1 addition & 1 deletion demo/App.fs
Expand Up @@ -23,7 +23,7 @@ let update msg state =
match msg with
| UrlChanged segments -> { state with CurrentUrl = segments }, Cmd.none
| NavigateUsers -> state, Router.navigate("users")
| NavigateToUser userId -> state, Router.navigate("users", [ "id", userId ])
| NavigateToUser userId -> state, Router.navigate("users", [ "id", userId ], HistoryMode.ReplaceState)

let render state dispatch =
let currentPage =
Expand Down
2 changes: 1 addition & 1 deletion src/Feliz.Router.fsproj
Expand Up @@ -6,7 +6,7 @@
<PackageIconUrl></PackageIconUrl>
<PackageTags>fsharp;fable;react;html;router;routing</PackageTags>
<Authors>Zaid Ajaj</Authors>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
Expand Down

0 comments on commit 8933c81

Please sign in to comment.