Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onBeforeRouteEnter not triggered if coming from reject route #244

Open
stackoverfloweth opened this issue Aug 15, 2024 · 2 comments
Open

Comments

@stackoverfloweth
Copy link
Contributor

I added a onBeforeRouteEnter hook to my route

const profile = createRoute({
	name: 'profile',
	path: '/profile',
	component: defineAsyncComponent(() => import('../components/ProfilePage.vue')),
	onBeforeRouteEnter: (to, { reject }) => {
		if (!activeUser.value) {
			reject('AuthNeeded')
		}
	},
})

works totally as expected the first time, if I try navigating to /profile without an active user the rejection happens, is handled by sending me to rejection route (doesn't matter if I use built in rejection component or custom). However, if I click a router-link again to go to /profile it seems to totally bypass this onBeforeRouteEnter hook.

@pleek91
Copy link
Contributor

pleek91 commented Aug 15, 2024

@stackoverfloweth is this when navigating from the rejection back to profile? Or just anytime you try and go to profile after hitting a rejection?

@stackoverfloweth
Copy link
Contributor Author

stackoverfloweth commented Aug 21, 2024

@pleek91 an update on this
I traced the issue to getBeforeRouteHooksFromRoutes, which takes to and from and returns all the hooks.

The first time I enter my route with this hook I see a hook in onBeforeRouteEnter where I'd expect
image

The second time I enter my route the onBeforeRouteEnter is empty
image

This line has a condition isRouteEnter, that is almost certainly the issue but I don't understand what it's trying to do assert.

I made a branch in our router-preview repo setup to reproduce
https://github.com/kitbagjs/router-preview/compare/issue-244-repro?expand=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants