router: fix middleware order behavior