navigo
navigo copied to clipboard
Root handler not invoked in v8
When running Navigo 7.1.2 as shown below:
console.log(`URL = ${window.location}`);
new Navigo(null, true /* hash = true */)
.on("/foo", () => console.log("foo handler"))
.on(() => console.log("root handler"))
.resolve();
… calling resolve()
invoked my root handler:
URL = http://localhost:10334/foo
root handler
After I upgraded to v8.11.0, my code looks like this:
console.log(`URL = ${window.location}`);
new Navigo("/", { hash: true })
.on("/foo", () => console.log("foo handler"))
.on(() => console.log("root handler"))
.resolve();
… but now the root handler is not called:
URL = http://localhost:10334/foo
foo handler
In v8, resolve()
seems to match routes based on the pathname (/foo
). This strikes me as weird – with hash: true
, shouldn't Navigo route based on the hash only?
Hey,
if you have has: true
then your browser journey should start with /#/foo
. Also I like to think that the hash routing is more of a supportive feature. The main usage should not use hashes. That's because hashes (in general) have another purpose and also because history based routing is well supported.
I have the same problem (at least i think)
const router = new Navigo("/", { hash: true });
router.on({
"/about": function () {
console.log("about");
},
});
Clicking on a link to http://127.0.0.1:5500/#/about works fine, but when i reload the page, the callback function is not invoked.
Ahh sorry i missed the resolve part
router
.on({
about: function () {
console.log("about");
},
})
.resolve();
Working now