mam*_*mcx 5 .net f# routes suave
我无法想象如何为路径设置路由器:
/store/category/%s/brand/%s
Run Code Online (Sandbox Code Playgroud)
我有网上商店演示,它适用于简单的URL,但我不知道如何使更灵活的配置.
这就是我所拥有的:
type StrPath = PrintfFormat<(string -> string),unit,string,string,string>
// How do this?
type Str2Path = PrintfFormat<(string -> string),unit,string,string,string>
let withParam (key,value) path = sprintf "%s?%s=%s" path key value
module Store =
//Don't know what put here
let browseBrand = sprintf "/store/category/%s/brand/%s"
//This work ok
let browseCategory : StrPath = "/store/category/%s"
// I need to capture query parameters
let browseBrand cat brand = request (fun r ->
Views.browse(cat brand))
let webPart =
localizeUICulture >>
choose [
path Path.Store.overview >=> overview
pathScan Path.Store.browseBrand browseBrand
pathScan Path.Store.browseCategory browseCategory
Run Code Online (Sandbox Code Playgroud)
那这个呢?
// note the string tuple as return value
type Str2Path = PrintfFormat<(string -> string -> string),unit,string,string,(string * string)>
module Store =
// your path
let browseBrand : Str2Path = "/store/category/%s/brand/%s"
// again, note the tuple as input
let browseBrand (cat, brand) = request (Views.browse(cat brand))
let webPart =
localizeUICulture >>
choose [
pathScan Store.browseBrand browseBrand
// ... OMMITED
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
134 次 |
| 最近记录: |