webmcp
diff framework/env/request/redirect.lua @ 113:ca88032cb37c
Anchor (#) support for redirect and routing
| author | jbe |
|---|---|
| date | Sun Jan 19 14:47:08 2014 +0100 (2014-01-19) |
| parents | 9fdfb27f8e67 |
| children | 56d237b81c18 |
line diff
1.1 --- a/framework/env/request/redirect.lua Mon Jan 13 21:40:27 2014 +0100 1.2 +++ b/framework/env/request/redirect.lua Sun Jan 19 14:47:08 2014 +0100 1.3 @@ -3,7 +3,8 @@ 1.4 module = module, -- module name 1.5 view = view, -- view name 1.6 id = id, -- optional id for view 1.7 - params = params -- optional view parameters 1.8 + params = params, -- optional view parameters 1.9 + anchor = anchor -- anchor in URL 1.10 } 1.11 1.12 Calling this function causes the WebMCP to do a 303 HTTP redirect after the current view or action and all filters have finished execution. If routing mode "redirect" has been chosen, then this function is called automatically after an action and all its filters have finished execution. Calling request.redirect{...} (or request.forward{...}) explicitly inside an action will cause routing information from the browser to be ignored. To preserve GET/POST parameters of an action, use request.forward{...} instead. Currently no redirects to external (absolute) URLs are possible, there will be an implementation in future though. 1.13 @@ -17,6 +18,7 @@ 1.14 local view = args.view 1.15 local id = args.id 1.16 local params = args.params or {} 1.17 + local anchor = args.anchor or nil 1.18 if type(module) ~= "string" then 1.19 error("No module string passed to request.redirect{...}.") 1.20 end 1.21 @@ -26,6 +28,9 @@ 1.22 if type(params) ~= "table" then 1.23 error("Params array passed to request.redirect{...} is not a table.") 1.24 end 1.25 + if anchor and type(anchor) ~= "string" then 1.26 + error("Anchor passed to request.redirect{...} must be a string or nil.") 1.27 + end 1.28 if request.is_rerouted() then 1.29 error("Tried to redirect after another forward or redirect.") 1.30 end 1.31 @@ -33,7 +38,8 @@ 1.32 module = module, 1.33 view = view, 1.34 id = id, 1.35 - params = params 1.36 + params = params, 1.37 + anchor = anchor 1.38 } 1.39 trace.redirect{ module = args.module, view = args.view } 1.40 end