Skip to content

Document dynamic routing #261

@thescientist13

Description

@thescientist13

Summary

In the next release, Greenwood will support dynamic routing for SSR pages and API routes, e.g.

Routing

src/
  pages/
    blog/
      [slug].js
    api/
      product/
        [id].js

SSR Page

export default class BlogPostPage extends HTMLElement {
  #slug: string;

  constructor({ params }) {
    super();
    this.#slug = params?.slug;
  }

  connectedCallback() {
    this.innerHTML = `
      <body>
        <h1>${this.#slug}</h1>
      </body>
    `;
  }
}

API Route

export async function handler(request: Request, { params }) {
  return new Response(`Product id is => ${params.id}`);
}

Additional Details

Things we need to document here - https://greenwoodjs.dev/docs/pages/routing/

Greenwood Issue

ProjectEvergreen/greenwood#882

Metadata

Metadata

Labels

docsGreenwood specific content like docs and guidesrelease/v0.34.0

Type

Projects

Status

🔖 Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions