1

I would like to interpret, for example a request like this:

GET /my/path?foo=bar

just as if it was actually rewritten to e.g.

GET /?path=/my/path&foo=bar

Now I thought I'll be able to achieve this using following route, and use param('path') along with param('foo') and the likes, e.g.:

get '/:path' => sub {
    return printf "...so you want %s, thinking that best foo is %s...",
        param('path'),
        param('foo');
}

but I get 404 -- It seems that the :path part cannot contain slashes.

Can I achieve this with routes at all? Or I'm looking at the wrong direction (I'm fresh new to Dancer)?

4

1 回答 1

1

您可能希望通过正则表达式而不是令牌来匹配路由。然后将匹配项存储在可以由关键字返回的特殊数组中splat。但是,您path将无法通过 访问param('path')

代码:

get qr{/([^?]*)} => sub {
    my ($path) = splat;
    return printf "...so you want %s, thinking that best foo is %s...",
        $path,
        param('foo');
}
于 2012-12-25T01:40:56.473 回答