I am building a gatsby app at https://sherpafeet.com
One of the issues I am seeing with client only routes is, if we refresh the page we get a 404, as it is a client only route and doesn't exist on the server.
Since we can do data fetching while loading a page, we could do a createPage on a template file in gatsby-node.js, so when should I be using client only routes vs a template file which does conditional rendering after fetching data at runtime?
Hope the question is clear!
Hello @Jaikant!
In order for client-side routes to work correctly, it should be supported by your server or CDN. See guide to setting up client-side routes.
Plugins like Netlify do it on a build. You could check out their source and create a universal tool to generate it on your website or specify it manually for your server if you only have a few of such routes.
I'll be closing this issue, feel free to reopen it if you have any questions.
@freiksenet As per the documentation, client only routes are for:
Often you want to create a site with client-only portions, which allows you to gate them by authentication or load different content based on URL parameters.
To gate information using authentication, we can do a fetch from within any page and conditionally render. We do not really need client only routes, correct me if I am wrong.
To load different content based on URL parameters - We can use templates to contruct different urls and pageContext to fetch data at runtime.
I am trying to grasp a use case for client only routes, which cannot be done without it.
re-opening issue.
To gate information using authentication, we can do a fetch from within any page and conditionally render. We do not really need client only routes, correct me if I am wrong.
While it is true that you can conditionally render anything you like, there are often "internal" admin pages (that are unique to every logged in user) which don't benefit from any build time SSR at all.
These are the sort of pages that client only routes are relevant for.
TL DR: If you want to skip build time SSR for a page and make it _client side only_, use a client only route.
Does that make sense? Happy to answer any other questions.
@sidharthachatterjee Thx that makes sense, the benefit being it could reduce build time.
@sidharthachatterjee oh yeah and also client routes are needed when we need to create urls at runtime :), for example when a new user signs up and we need a new url to represent his profile page.