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.

Issues when trying to implement sub routing system on page created through "createPage"

See original GitHub issue

Summary

I am struggling to implement a sub-routing system on a page which is created through createPage.

I need the default sub-route of the page to be built to static html but also, any subsequent sub-routes on the same page need to be client only. This has led to me having two routers for the same page. One on the template used for createPage and then one on the page component I use for the matchPath assignment.

The issue I am getting is that the template component is rendering for the default sub-route and then for any other sub-routes the page component is, resulting in full page flashes and data updating when it shouldn’t be.

Have replicated my approach in this codesandbox. Make sure to go to https://hkhbb.sse.codesandbox.io/test/foo/bar to see the output.

I go into detail about my issues on #14954. I thought I had got round the issue but it has since returned since updating to latest gatsby (2.13.45). Is this the correct approach when trying to achieve what I am trying to achieve?

Thanks!

EDIT: I should mention that I have around 25k pages generated which need to have this sub routing system on. I have tried adding a matchPath directly in createPage but this inflates the JS bundle massively because of an array containing matchPath data.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
herecydevcommented, Jun 5, 2020

The example I’ve put in there is unrelated to your issue here, but it highlights that there are multiple further ways that people want to use it.

It could be that the matchPaths is extended to allow user-defined functions:

//i.e. path is /posts/123/edit
path => {
if(path.match(/posts\/\d+/) {
// return the correct static route, i.e. /posts/123
} else {
return null
}
1reaction
pbricklescommented, Aug 5, 2019

I have had a similar issue when trying to create a “tab”-like sub navigation on a page. I would be interested to see if the approach is valid or not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gatsby hybrid app - Issues with sub routing on a page which is ...
I need to create a page using createPage which contains a sub-routing system in which the default route is built to static HTML,...
Read more >
Creating client-only sub-routes for static pages, /item/:id/edit
dandv mentioned this issue on Jun 4, 2020. Issues when trying to implement sub routing system on page created through "createPage" #16250.
Read more >
Creating and Modifying Pages - Gatsby
Gatsby makes it easy to programmatically control your pages. Pages can be created in three ways: By creating React components in the src/pages...
Read more >
How to Create Pages in Next.js with Static & Dynamic Data
we want to render statically. Let's start off by creating a new directory characters inside of pages and inside, create a new file...
Read more >
The Guide to Nested Routes with React Router - ui.dev
In this comprehensive, up-to-date guide, you'll learn everything you need to know about creating nested routes with React Router.
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