How does one escape the # sign in a Url pattern in

2019-08-12 12:32发布

In order to maintain the current set of Urls in a project, I have to be able to use the # (pound sign) in the Url. For some reason the pound sign does not appear to work normally in this project for UrlMappings.groovy.

Is there a special escape-sequence that must be used when placing # signs in UrlMappings.groovy?

Am I missing some reason why one cannot use pound signs at all?

In the following URL Mapping example, the browser goes to the correct page, but the pageName variable is null:

"/test/${urlName}#/overview"(controller:'test', action:'overview') {
    pageName = "overview"
}

2条回答
\"骚年 ilove
2楼-- · 2019-08-12 12:38

I thought everything after # in the url would be treated on the client side of the browsers where it tries to find a and scroll to that location.

If you dump the request containing the pound char, do you even see the data behind #?

查看更多
Fickle 薄情
3楼-- · 2019-08-12 12:56

I used a Named URL mapping and it works fine, no need to escape the "#" sign:

name test: "/#abc" (controller: 'test', action:'homepage')

EDIT: My above answer is wrong. In fact, it falls to a special case when homepage is the default action of the view.

Netbrain is right, the path after "#" will never be sent to server. In stead, I found that it's possible using "%23" instead of "#". Please take a look at here.

For example, instead of /test#/abc we should use /test%23/abc as URL mapping (both at client side & server side).

查看更多
登录 后发表回答