-
How do I create custom routing for |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Here are the instance HasPath CategoriesController where
pathTo CategoriesAction = "/categories"
pathTo NewCategoryAction = "/category/new"
pathTo CreateCategoryAction = "/category/create"
pathTo ShowCategoryAction { categoryId } = "/category/" <> tshow categoryId
pathTo EditCategoryAction { categoryId } = "/category/edit/" <> tshow categoryId
pathTo UpdateCategoryAction { categoryId } = "/category/update/" <> tshow categoryId
pathTo DeleteCategoryAction { categoryId } = "/category/delete/" <> tshow categoryId
instance CanRoute CategoriesController where
parseRoute' = do
let categories = do
string "/categories"
optional "/"
endOfInput
pure CategoriesAction
let newCategory = do
string "/category/new"
optional "/"
endOfInput
pure NewCategoryAction
let createCategory = do
string "/category/create"
optional "/"
endOfInput
pure CreateCategoryAction
let showCategory = do
string "/category/"
categoryId <- parseId
optional "/"
endOfInput
pure ShowCategoryAction { categoryId }
let editCategory = do
string "/category/edit/"
categoryId <- parseId
optional "/"
endOfInput
pure EditCategoryAction { categoryId }
let updateCategory = do
string "/category/update/"
categoryId <- parseId
optional "/"
endOfInput
pure UpdateCategoryAction { categoryId }
let deleteCategory = do
string "/category/delete/"
categoryId <- parseId
optional "/"
endOfInput
pure DeleteCategoryAction { categoryId }
categories <|> newCategory <|> createCategory <|> showCategory <|> editCategory <|> updateCategory <|> deleteCategory
Keep in mind that functions such as Read more about custom routing here |
Beta Was this translation helpful? Give feedback.
-
Q: How to create a route like this A: Add this to the let categoryQuestions = do
string "/categories/"
categoryId <- parseId
string "/questions/"
questionId <- parseId
optional "/"
endOfInput
pure MyAction { categoryId, questionId } And, this to the pathTo MyAction { categoryId, questionId } = "/categories/" <> tshow categoryId <> "/questions/" <> tshow questionId |
Beta Was this translation helpful? Give feedback.
-
Here is also a demo project that showcases how to achieve custom routing with a one-to-many relationship. |
Beta Was this translation helpful? Give feedback.
Here are the
HasPath
andCanRoute
instances for custom routing, they belong in theWeb.Routes
orAdmin.Routes
module