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.LinkHash #285

Open
granicz opened this issue May 3, 2024 · 0 comments
Open

Add Router.LinkHash #285

granicz opened this issue May 3, 2024 · 0 comments

Comments

@granicz
Copy link
Member

granicz commented May 3, 2024

Currently, the Router type from WebSharper.Sitelets is available for client-side use through a macro. This enables creating routers for endpoint types on the client, which is often used in SPAs in combination of hashed URLs:

open WebSharper.Sitelets
open WebSharper.UI

// SPA endpoints
type EndPoint =
    | [<EndPoint "/">] Home
    | [<EndPoint "/counter">] Counter

// Creating a client-side router
let router = Router.Infer<EndPoint>()
// Installing it and tracking the current page via an RV
let currentPage = Router.InstallHash EndPoint.Home router

Given this, it would be desirable to be able to compute hash-based URLs, instead of manually accounting for the hash - which looks something like:

IndexTemplate()
    .Url_Home("/#" + router.Link EndPoint.Home)

This ticket would add this as an extension member to Router<'T>, when WebSharper.UI is opened.

type Router<'T when 'T: equality> with
    member this.LinkHash (ep: 'T) = "/#" + this.Link ep
@Jooseppi12 Jooseppi12 self-assigned this May 6, 2024
Jooseppi12 added a commit that referenced this issue May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: v7.0
Development

No branches or pull requests

2 participants