Fixed routes with fragments in the URL

The previous implementation would put the query after the fragment, which is incorrect. It should be the query followed by the fragment.