Use the beforeRouting branch of the router.