I just published a bug fix (WebSharper 3.6.18) which allows you to use the Wildcard
attribute for this:
type EndPoint =
| [<EndPoint "/">] Home
| [<EndPoint "/about">] About
| [<EndPoint "/"; Wildcard>] AnythingElse of string
[<Website>]
let Main =
Application.MultiPage (fun ctx endpoint ->
match endpoint with
| EndPoint.Home -> HomePage ctx
| EndPoint.About -> AboutPage ctx
| EndPoint.AnythingElse path -> Content.NotFound // or anything you want
)
Note though that this will catch everything, even URLs to files, so for example if you have client-side content then urls like /Scripts/WebSharper/*.js
will not work anymore. If you want to do that, then you'll need to drop to a custom router:
type EndPoint =
| [<EndPoint "/">] Home
| [<EndPoint "/about">] About
| AnythingElse of string
let Main =
Application.MultiPage (fun ctx endpoint ->
match endpoint with
| EndPoint.Home -> HomePage ctx
| EndPoint.About -> AboutPage ctx
| EndPoint.AnythingElse path -> Content.NotFound // or anything you want
)
[<Website>]
let MainWithFallback =
{ Main with
Router = Router.New
(fun req ->
match Main.Router.Route req with
| Some ep -> Some ep
| None ->
let path = req.Uri.AbsolutePath
if path.StartsWith "/Scripts/" || path.StartsWith "/Content/" then
None
else
Some (EndPoint.AnythingElse path))
(function
| EndPoint.AnythingElse path -> Some (System.Uri(path))
| a -> Main.Router.Link a)
}
(copied from my answer in the WebSharper forums)