-
Notifications
You must be signed in to change notification settings - Fork 251
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
Routing hooks error #281
Comments
You should not call the |
So if i remove done(), router.navigate will not work? |
Hm ... interesting. Can you try with |
Before hook Thats all ((( |
Sorry, I did not look at your code in details. So what is happening is that you are defining a hook for every route. Including router
.on('/auth', () => {
console.log('Auth');
});
.on('/', () => {
console.log('Home');
}, {
before(done) {
router.navigate("/auth");
done(false);
}
}) The |
Your code dosn't work too And this code too: router.hooks({
before(done, match) {
console.log(match.url);
if (match.url !== 'auth') {
console.log('Before hook');
router.navigate("/auth");
done(false);
} else {
done();
}
}
}); |
I need to make something like middleware to check auth, so i want use global hook for all routes except auth |
I see. let me come with a test case. |
Hey @Wayfindertm, there was a bug which is fixed in a new describe("and we want to navigate out from a hook", () => {
it("should properly land on the new path", () => {
const r: NavigoRouter = new Navigo();
const h1 = jest.fn();
const h2 = jest.fn();
r.hooks({
before(done, match) {
if (match.url !== "auth/sign-in") {
r.navigate("/auth/sign-in");
done(false);
} else {
done();
}
},
});
r.on("/auth/sign-in", h1);
r.on("/", h2);
r.resolve();
expect(h1).toBeCalledTimes(1);
expect(h2).not.toBeCalled();
});
}); |
It works great!!! Thanx!!! |
And when we call home route we see in console:
How can a force open auth without calling home?
The text was updated successfully, but these errors were encountered: