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.

AKA routes that look like

<Route path='posts/:id' component={Post} />

The issue

We need dynamic routes to support creating an entire category of sties including blogs. However currently we don’t have a way to turn something like posts/:id into a file directly. Normally we would have something like this:

posts/
  hellow-world.md
  second-post.md
  still-here.md

Which would generate the following HTML…

posts/
  hello-world.html
  second-post.html
  still-here.html

But in our case React Router has no way of knowing the contents of our posts/ directory so how would it know what files to generate?

Most static site generators would read the posts/ directory and then generate static sites from those files. However, that requires the user to either learn how to configure their generator or learn the conventions for creating dynamic content.

We could do the same thing:

fs.readdirSync('./posts').forEach(filename => {
  // 1. Read contents of file
  // 2. Generate a static HTML file for it
});

But then the user would have to know how to hook into this process. It is a first-class goal of this project to not force the user to learn some new technology. Just add this plugin to a webpack config and go. This is the issue I’d like to solve.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:2
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
iansinnottcommented, Aug 22, 2016

Hey @sidjain26 thanks for the ping. I haven’t looked at this issue in a while, because for whatever reason I haven’t yet run into the need for dynamic routes. I’ve been using this plugin extensively but it’s all been for sites without dynamic routing.

In my own minimal testing in the past the context approach actually worked quite well. it’s currently the option I favor because it is explicit and doesn’t require the user to know any special configuration—this is a first class goal of this project.

What’s also nice is that the require.context approach should work out of the box right now, because it doesn’t require any specific configuration within this plugin. It’s simply leveraging a feature of webpack. So although I don’t currently have a guide for how to do this it should be a viable option for anyone wanting to implement dynamic routes.

Once I rewrite my blog using this plugin I will definitely figure out how to do dynamic routing.

0reactions
iansinnottcommented, Nov 10, 2016

@lifeiscontent I’m not sure, but my guess is that Webpack has a i18n solution. Have you tried internationalizing a web app with webpack yet?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Routes - Next.js
Dynamic Routes are pages that allow you to add custom params to your URLs. Start creating Dynamic Routes and learn more here.
Read more >
Routing in Next.js – How to Set Up Dynamic Routing with Pre ...
In this tutorial, you'll learn how to set up dynamic routing in Next.js. You'll also learn about pre-rendering and why it's important.
Read more >
Static vs. dynamic routing: What is the difference? - TechTarget
Dynamic routing, sometimes called adaptive routing, is more complex than static routing because it creates more possible routes to send packets across a ......
Read more >
How to Create Dynamic Routes in Next.js - MakeUseOf
Dynamic routes are pages that allow you to use custom parameters in a URL. They are especially beneficial when creating pages for dynamic ......
Read more >
Dynamic routing - Wikipedia
Dynamic routing, also called adaptive routing, is a process where a router can forward data via a different route for a given destination...
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