preact-async-route icon indicating copy to clipboard operation
preact-async-route copied to clipboard

Function passed to getComponent is never called

Open devmattrick opened this issue 7 years ago • 5 comments

Hi!

I have a very basic setup as follows:

import { h, render } from "preact";
import AsyncRoute from "preact-async-route";
import Router from "preact-router";

import Index from "./pages/Index";

function getTest() {
  console.log("test");

  return import("./pages/Test").then(module => module.default);
}

const App = () => (
  <Router>
    <Index path="/" />
    <AsyncRoute path="/test" getComponent={getTest} />
  </Router>
);

render(App(), document.body);

When I try to navigate to /test, however, it simply renders <undefined path="/" url="/"></undefined>, instead of the expected component. I've also noticed that the console.log statement is never called. There are no errors at compile time or in the console at runtime.

If you need anything else, please let me know!

devmattrick avatar Feb 10 '19 03:02 devmattrick

I got the same problem here, Even though I copied their example but it doesn't work either.

daricvn avatar Jul 14 '19 02:07 daricvn

Sorry for the late reply was a bit occupied I tried your code above... seems to be working fine:

https://codesandbox.io/s/gifted-buck-edzwo

prateekbh avatar Jul 29 '19 05:07 prateekbh

I don't think I have the code I was working on still, but I'll try to see if I can reproduce the issue and if so I'll post the repo here.

devmattrick avatar Jul 30 '19 00:07 devmattrick

I haven't been able to find a way to reproduce it, I initially thought the issue may be with Preact X, but it doesn't seem to be causing any problems. Maybe @daricvn would be willing to share their code, otherwise it's probably fine to close this issue.

devmattrick avatar Aug 08 '19 01:08 devmattrick

Also Preact X has lazy. you dont even need this.

prateekbh avatar Aug 08 '19 01:08 prateekbh