← Home

Elder.js Route: An Overview

How Routing Works:

Elder.js's routing flow is different from what you'll see in other frameworks such as express.

Most frameworks define routes like so: /blog/:slug/.

Then when you visit /blog/simple/ that route would receive a request object of { slug: "simple" }.

While this approach works, a huge downside is that it forces a static site generator to crawl all of the links on a site to know all of the request objects.

Since Elder.js is built for speed and crawling is expensive, Elder.js asks you to define all of your request objects in your all() function.

Once it has your requests, it runs them through the permalink() function to can build an entire map of your site so we don't have to crawl it but can generate it on the fly.

Learning Exercise:

Try adding { slug: "another-request" } to the all() function in ./src/simple/route.js and then visit /another-request/ to see that you added another page with the same data.