Programmatically prefetching #20568
Replies: 7 comments
-
Super interesting @ThewBear! I would also have a use case for it, from #20745. "These solutions" is talking about access control - denying access per-user and per-page on an Express static file server, which will cause failed requests with pre-fetching.
|
Beta Was this translation helpful? Give feedback.
-
@ThewBear Could you share your current solution with us? I may use it in the interim to work around the failed requests in my proof of concept Gatsby + server-side Auth0 + Express repo: https://github.com/karlhorky/gatsby-serverside-auth0 |
Beta Was this translation helpful? Give feedback.
-
@karlhorky I call import React, { useEffect } from "react";
import { navigate } from "gatsby";
const Page1 = () => {
useEffect(() => {
/* global ___loader */
___loader.enqueue("/page-2");
}, []);
return <button onClick={() => navigate("/page-2")}></button>
}
gatsby/packages/gatsby-link/src/index.js Line 70 in 721e9d1 |
Beta Was this translation helpful? Give feedback.
-
Ah interesting. I guess a new Gatsby <Link prefetch={isAllowed(user, page)} /> I'll have to see whether this is useful enough for us. If so, maybe I'll implement + publish this too. |
Beta Was this translation helpful? Give feedback.
-
Not sure why |
Beta Was this translation helpful? Give feedback.
-
This is something that Next.js implements and would be really helpful to have in Gatsby. |
Beta Was this translation helpful? Give feedback.
-
Well, its been over a year, are there still plans for some sort of programmatic prefetch like
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Currently gatsby-link prefetch route on
Link
componentcomponentDidMount
.gatsby/packages/gatsby-link/src/index.js
Lines 74 to 79 in 762506f
It would be great if we also support some kind of prefetch for
navigate
function or a new programmatically prefetch page function. My current solution is usingwindow.___loader.enqueue
which is technically unsupported.gatsby/docs/docs/production-app.md
Line 120 in 6f3eb97
Beta Was this translation helpful? Give feedback.
All reactions