Skip to content

Instantly share code, notes, and snippets.

@Kimserey
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kimserey/827058f2277927170003 to your computer and use it in GitHub Desktop.
Save Kimserey/827058f2277927170003 to your computer and use it in GitHub Desktop.
Simplistic implementation of SPA by changing page based on a Page reactive variable. Websharper blog post, Structuring Non-Linear Sites: http://websharper.com/blog-entry/3965/structuring-web-applications-with-websharper-ui-next
namespace UINextRouterTest
open WebSharper
open WebSharper.JavaScript
open WebSharper.JQuery
open WebSharper.UI.Next
open WebSharper.UI.Next.Html
open WebSharper.UI.Next.Client
[<JavaScript>]
module Client =
type Page = Home | Configuration | Account
type Context = { Go: Page -> unit }
let HomePage ctx =
Doc.Concat [
h1 [text "Home"]
p [ text "Blabla some stuff in the home" ]
Doc.Link "link to go to config" [] (fun _ -> ctx.Go Configuration) ]
let ConfigurationPage ctx =
Doc.Concat [
h1 [text "Config"]
p [ text "Blabla config stuff config in the config" ]
Doc.Link "link to go to account" [] (fun _ -> ctx.Go Account) ]
let AccountPage ctx =
Doc.Concat [
h1 [text "Account"]
p [ text "Blabla account stuff account in the account" ]
Doc.Link "link to go to home" [] (fun _ -> ctx.Go Home) ]
let Main =
let rvPage = Var.Create Home
let context = { Go=Var.Set rvPage }
let doc =
rvPage.View
|> View.Map (function
| Home -> HomePage context
| Configuration -> ConfigurationPage context
| Account -> AccountPage context)
|> Doc.EmbedView
Doc.RunById "main" doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment