Dancer2 icon indicating copy to clipboard operation
Dancer2 copied to clipboard

`prefix` peculiarities

Open ialarmedalien opened this issue 10 years ago • 1 comments

Not sure if this is a bug or a feature, but it should be documented. If you are using prefix and have your routes spread across several packages, you need to ensure that prefix is undefined at the end of each package of routes, or you'll get weird 404 errors. My situation:

I've got a wrapper app that holds all my routes:

package WrapperApp;
use Routes::Here;  ## routes starting with /here
use Routes::There; ## routes starting with /there
1;

I was using the prefix '/here'; syntax because I kept getting strange 404 errors with the prefix '/here' => sub { ... }; syntax.

I added a new package with a /test route, but got 404s whenever I tried to access it. By chance, I tried /there/test, which returned my test page. When I set prefix to undef at the end of Routes::There, I could access /test correctly. Swapping around the order of the packages in WrapperApp demonstrated that the prefix from the previously-listed package was carried over. When I converted all of my prefixed routes to the prefix '/blah' => sub { ... }; syntax, or added prefix undef to each package, the problem vanished.

This may be an edge case, but I think it's worth adding something to the docs about undefining prefix at the end of each package if you're using the prefix '/blah' syntax.

On a different note, it would be really useful if prefixacted more like the route handlers (get,post, etc.) and you could set variables (using var) and do other such things based on the partial route match provided by prefix.

ialarmedalien avatar Oct 01 '15 19:10 ialarmedalien