我在 CRUD 之上添加了一些操作,并且我想要自定義路由到新操作。但是,保持 CRUD 操作使用相同的路由(例如/ShowPost?postId=[uuid]
instance HasPath PostsController where
-- ...
pathTo ShowPostAction { postId } = "/ShowPost?postId=" tshow postId
instance CanRoute PostsController where
parseRoute' = do
let posts = do
string "/Posts"
optional "/"
endOfInput
pure PostsAction
let showPost = do
string "/ShowPost?postId="
postId <- parseId
optional "/"
endOfInput
pure ShowPostAction { postId }
posts <|> showPosts -- ...
我假設該CanRoute部分沒有正確決議,因為導航到時我最終得到一個 404 頁面/ShowPost?postId=...
uj5u.com熱心網友回復:
這里的問題是它?postId=不是請求路徑的一部分,因為它是請求的查詢字串的一部分。
給定一個請求/ShowPost?postId=abc,那么決議器輸入實際上就是/ShowPost. ?postId=abc只能通過變數?context獲得。
您可以嘗試這樣的事情(未經測驗):
instance HasPath PostsController where
-- ...
pathTo ShowPostAction { postId } = "/ShowPost?postId=" tshow postId
-- Define the auto route instance
instance AutoRoute PostsController
instance CanRoute PostsController where
parseRoute' = do
let customRoutes = ...
customRoutes <|> (autoRoute @PostsController)
基本上,這將首先使用您的customRoutes決議器,然后嘗試通過AutoRoute.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/423018.html
標籤:
