moon-router icon indicating copy to clipboard operation
moon-router copied to clipboard

Moon ignoring History Mode

Open sconeyard opened this issue 8 years ago • 9 comments

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
      });

sconeyard avatar Aug 28 '17 13:08 sconeyard

Have you used Moon.use(MoonRouter) at the top?

kbrsh avatar Aug 28 '17 14:08 kbrsh

Yes, I did. Cropped that out accidentally. Also the routing itself works, its just that the Hashbang remains with history mode.

sconeyard avatar Aug 28 '17 14:08 sconeyard

Ahh, thanks! I'll look into it.

kbrsh avatar Aug 28 '17 14:08 kbrsh

So this structure is a little weird and a bad practice.

  1. Try to have one Moon instance. Replace the "header" instance with a component.
  2. data() should return an object representing the data for a component.
  3. Try using the mounted hook to emit an event that the header component can listen to.

kbrsh avatar Aug 28 '17 14:08 kbrsh

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.

oliverguj avatar Sep 21 '17 12:09 oliverguj

Ahh yes. @oliverguj

History mode will be supported in Moon Router v1, along with Moon v1.

kbrsh avatar Sep 21 '17 13:09 kbrsh

@kbrsh When is V1 coming? I stumbled across this and it looks awesome.

NetOpWibby avatar Oct 15 '17 09:10 NetOpWibby

@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 :)

kbrsh avatar Oct 15 '17 16:10 kbrsh

Sounds good!

NetOpWibby avatar Oct 16 '17 00:10 NetOpWibby