Skip to content

Direct Routing Support #76

@dgp1130

Description

@dgp1130

So I was originally expecting that @rules_prerender wouldn't really need a routing solution because it would be generic enough to support any kind of site routing. The export default entry broad is powerful enough to mostly do whatever users could want to do. However, while working on the docs site, I've changed my mind for a couple reasons.

  1. If a page attempts to render a navigation UI which lists all the pages, then you need to know all page URLs up front before you can render a single page. This logic gets almost circular and it can be tricky to manage.
  2. It is very useful for a rendered page to know where it lives in the router hierarchy and requires a lot of duplicated information if it is not tightly integrated into the route configuration.

I'm working on a proof-of-concept directly in the docs site, but I think upstreaming a more comprehensive implementation would be very useful. Currently this looks something like:

import { bootstrap } from 'rules_prerender';

export default bootstrap([
  {
    label: 'Home',
    path: '/',
    render: (currentRoute, routes) => renderToHtml(<div>Hello, World!</div>),
  },
  {
    label: 'Tutorials',
    path: '/tutorials',
    // No render function, no page is created.
    children: [
      {
        label: 'Getting Started',
        path: 'getting-started',
        render: (currentRoute, routes) => renderToHtml(<MyNav currentRoute={currentRoute} routes={routes} />),
      },
    ],
  },
]);

The exact shape of this is TBD, but some requirements to consider based on this use case:

  1. A means of hiding routes from the navigation (privacy, not found).
  2. A means of generating parameterized routes like /products/:id.
  3. Application-specific data attached to individual routes in a type-safe manner.
  4. Two-way pointers to navigate the route tree from the current route.
  5. Route composition between different targets.
  6. Some means of discovering routes automatically? Perhaps through file-based mechanisms?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions