FredKSchott / esm-hmr

a Hot Module Replacement (HMR) API for your ESM-based dev server.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Trouble staying on the same route

chrisandrewca opened this issue · comments

commented

Hi! Thanks for the hmr module, super cool.

I'm having trouble staying on the same route. What I mean is if I'm on /product and edit some code & save. I end up back at the root /.

I'm using plain JS with pushState + CustomEvent for location changes and onpopstate for forward/back buttons.

My app looks like

const App = async () => {

  const pages = [
    { path: /^[/]$/, load: async () => (await import('./home')).default },
    { path: /^[/]product$/, load: async () => (await import('./product')).default }
  ];

  onLocationChanged(async () => {
    const location = matchLocation(pages);
    const content = await location.page.load();

    render(content(), window.document.body);
  });

  replaceLocation('/');
};

export default App;

if (import.meta.hot) {
  import.meta.hot.accept();
}
commented

Hah rubber ducking - it was the replaceLocation() that I'm using to kick off my rendering.... I'll need figure out another way to do that.