I have an annoying situation where I need to hook into every route change to check something. If condition X is true, I need to redirect to the homepage by showing a notice only on that single pageview. So I have the following:
router.beforeEach(() => {
if (...) {
store.showIneligibleBanner();
return { path: '/' };
}
// in all other cases hide the banner
store.hideIneligibleBanner();
return true;
});
The problem is when I return { path: '/' }
this triggers the beforeEach a second time and the conditional no longer applies. I know I could create more variables to keep track but I wanted a cleaner approach.
I am really just trying to show a banner a single time on that return redirect.