Handle optional trailing slashes in route definition.

It is common to add ```/?``` at the end of your route definitions to make them work with or without trailing slashes, however doing so can result in the generation of paths like ```/path/??key=value```.

This patch simply removes any ```/?``` from the end of the generated path before any query params are appended.