An npmsearch for pushState showed me substack's single-page module.

The module exemplifies the idiom do one thing well.

I set out looking for a router, but the self-proclaimed tiny ones had extra bulk in them to do hash routing, which I have no interest in right now. In contrast, single-page is like a framework for router plugins: You define your own router and single-page calls your router when the URL changes.

var showPage = singlePage(function myrouter(href) { ... });
showPage('/informal/thank-you-substack');

I wonder: do all of the other routers out there seamlessly plug into single-page? I don't know... It seems to me that they do a lot of extra non-routing junk. Aha! Suddenly this arbitrary, technically-non-routing library is illuminating my idea of what a router is. What are the minimal responsibilities that make something be a router? What does it mean for a router to do one thing well?

Although it does not boast about its small stature, single-page is genuinely tiny! And to me it is epiphanic.

Open Problems

  • How does this contrast with directly using browser pushState?
  • What are all the ways we can declare routes in a router?

  • Does a router have a purpose without single-page?
  • Does single-page have a purpose without a router?