question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gatsby App - Templates vs Client only routes

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sidharthachatterjeecommented, Jan 10, 2020

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.

1reaction
Jaikantcommented, Jan 9, 2020

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Client-only Routes & User Authentication - Gatsby
Client-only routes will exist on the client only and will not correspond to index.html files in an app's built assets in the /public...
Read more >
Using client-only routes with page templates coming from ...
I assume that gating content from a CMS is possible with Gatsby but I might be wrong given it is an SSG. I...
Read more >
App-Like Features of Gatsby – Create Client-Only Routes
Create Client-Only Routes. While Gatsby is extremely powerful at prerendering content, it's also great for client-only apps. With the addition of dynamic ...
Read more >
gatsby-example-client-only-paths - CodeSandbox
CodeSandbox is an online editor tailored for web applications. ... gatsbyjs / gatsby-starter-default / master ... gatsby-example-client-only-paths.
Read more >
Gatsby Tutorial #3 - Pages & Routes - YouTube
Hey gang, in this Gatsby tutorial we'll talk about how to create pages (page components) and the routes generated for those pages.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found