申し訳ありませんが、これは非常に長い投稿です
F# と WebSharper を使用しています (どちらのテクノロジも初めてです)
いくつかのエンドポイントが定義されています (NotFound エンドポイントを追加するまで、動作するコードがあります)
type EndPoint =
| [<EndPoint "/">] Home
| [<EndPoint "/login">] Login
| [<EndPoint "/about">] About
| [<EndPoint "/logout">] Logout
// trying to make a catch-all page handler
| [<EndPoint "/"; Wildcard>] NotFound of string
...
let HomePage ctx =
Templating.Main ctx EndPoint.Home "Home" [
// page stuff
]
let LoginPage ctx =
Templating.Main ctx EndPoint.Login "Login" [
h1 [] [text "Login Here"]
div [] [client <@ Client.LoginWidget() @>]
]
// other page constructs
let MissingPage ctx path =
Templating.Main ctx EndPoint.About "Page Not Found" [
h1 [] [text "404"]
p [] [text "The requested page could not be found"]
p [] [text path]
]
...
[<Website>]
let Main =
Application.MultiPage (fun ctx endpoint ->
match endpoint with
| EndPoint.Home -> HomePage ctx
| EndPoint.About -> AboutPage ctx
| EndPoint.Login -> LoginPage ctx
| EndPoint.Logout ->
async {
// call server-side code to log the user out
// what would i do here to redirect the user to the /login
// page
}
| EndPoint.NotFound path -> MissingPage ctx path
)
NotFound エンドポイントを追加すると、他のページが台無しになります。たとえば、ホームページが MissingPage ハンドラーによって処理され始めます。ホームページは「/」に一致するように設定されており、not パターンは「/」ワイルドカードに一致するため、理解できますが、単一の / が Home エンドポイントと /Login /About 以外のものと一致すると予想していました。 /Logout は、NotFound ブランチと一致するようにします。しかし、明らかに、私は何かを正しく理解していません。
では、明示的に提供されていないパスを適切に処理できるように、「キャッチオール」タイプのエンドポイントを取得するにはどうすればよいですか
NotFound 処理コードを持っていたときに台無しになっているもう 1 つのことは、ログイン ハンドラーが処理されなくなったことです。
div [] [client <@ Client.LoginWidget() @>]
最後に、Logout ハンドラーで、サーバー側のコードを呼び出したいのですが (問題ありません)、新しい Web ページにリダイレクトするにはどうすればよいですか? たとえば、ユーザーを /login ページに戻すにはどうすればよいでしょうか?
このような長い投稿でもう一度申し訳ありません