Moon ignoring History Mode
Hey, so I am building a SPA using Moon. I use the router in history mode to avoid the Hashbang URL. Altough I provide the history mode setting I still get the hashbang. I am not usually a JS-dev andddd the Browser Console was empty so I do not know what I could provide to make this Issue more helpful. So here is a little code I used.
Moon.use(MoonRouter);
const router = new MoonRouter({
default: "/",
map: {
"/": "Root",
"/hello": "Hello"
},
mode: "history"
});
Moon.component("Root", {
data : function() {
header.set('title', "ROOT");
},
template: `<div>
<h1>Welcome to "/"</h1>
<router-link to="/hello">To /hello</router-link>
</div>`
});
Moon.component("Hello", {
data : function() {
header.set('title', "HELLO");
},
template: `<div>
<h1>You have Reached "/hello"</h1>
<router-link to="/">Back Home</router-link>
</div>`
});
const header = new Moon({
el: "title",
data: {
title: "Loading..."
}
});
new Moon({
el: "#app",
router: router
});
Have you used Moon.use(MoonRouter) at the top?
Yes, I did. Cropped that out accidentally. Also the routing itself works, its just that the Hashbang remains with history mode.
Ahh, thanks! I'll look into it.
So this structure is a little weird and a bad practice.
- Try to have one Moon instance. Replace the "header" instance with a component.
data()should return an object representing the data for a component.- Try using the
mountedhook to emit an event that theheadercomponent can listen to.
I think the problem is that version 0.1.3 simply does not include the history API code. There is no string "history" in https://unpkg.com/[email protected]/dist/moon-router.js – compare with latest dist on github: https://raw.githubusercontent.com/kbrsh/moon-router/master/dist/moon-router.min.js
History mode was introduced in August https://github.com/kbrsh/moon-router/commit/488441e409eac010b061b3f1fee6b354eea5c57e but latest realease version 0.1.3 was built in July.
Ahh yes. @oliverguj
History mode will be supported in Moon Router v1, along with Moon v1.
@kbrsh When is V1 coming? I stumbled across this and it looks awesome.
@NetOperatorWibby v1 alpha is scheduled to be released within the next two weeks. After that will be an alpha and release candidate to squash any more final bugs. So v1 should be coming in early 2018 :)
Sounds good!