Grails URL mapping to always show www.mysite.com in browser address bar
I have grails application which has several controllers and actions. Suppose a user goes to:
http:// www.mysite.com/user/register
which means action register in controller user is executed. what I want is that when the response is r开发者_如何学编程eceived by the browser ( or when the request is made by the browser), the browser URL bar should display (the root path): http:// www.mysite.com
without executing the default action and controller (mapped to the root path '/' in the URLMappings.groovy).
Is this possible and how to do that?
You can either redirect to root controller+action:
redirect controller: "home", action: "index"
(though this will call the action, is it that you're trying to aviod?) or call
render template:'some_template', model: '[some: model]'
for root page. It will work if you extract root page elements to a template and have a simple model in it. We, for instance, have no model at all for a root page.
If you wish to always stay on root page, you'll have to use redirect
: how can browser go from action page to root page without being told to?
I believe you can use params
property of redirect method, or flash variable, to tell the root action what to do and what not to do.
精彩评论