inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.55k stars 435 forks source link

TypeError: n.get() is undefined when trying to prefetch with the router #2053

Open nick-potts opened 1 month ago

nick-potts commented 1 month ago

Versions:

Describe the problem:

From a layout, I'm trying to call prefetch programmatically but it results in an error.

useEffect(() => {
      router.prefetch(
          "/users",
          { method: "get", data: { page: 2 } },
          { cacheFor: "1m" }
      );
}, []);
Uncaught (in promise) TypeError: n.get() is undefined
    getHeaders request.ts:137
    send request.ts:49
    send requestStream.ts:18
    prefetch router.ts:220
    v prefetched.ts:36
    add prefetched.ts:35
    prefetch router.ts:217
    default DefaultLayout.tsx:23
    default DefaultLayout.tsx:22
    React 13
    workLoop scheduler.development.js:266
    flushWork scheduler.development.js:239
    performWorkUntilDeadline scheduler.development.js:533
    scheduler chunk-QANAYWAR.js:405
    scheduler chunk-QANAYWAR.js:453
    __require chunk-WOOG5QLI.js:12
    scheduler chunk-QANAYWAR.js:465
    __require chunk-WOOG5QLI.js:12
    React 2
    __require chunk-WOOG5QLI.js:12
    dom React
    __require chunk-WOOG5QLI.js:12
    dom React
    __require chunk-WOOG5QLI.js:12
    <anonymous> react-dom_client.js:38