Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server side routes should support dynamic route naming (with prerendering) #882

Open
1 of 5 tasks
thescientist13 opened this issue Feb 10, 2022 · 0 comments
Open
1 of 5 tasks

Comments

@thescientist13
Copy link
Member

thescientist13 commented Feb 10, 2022

Type of Change

  • New Feature Request
  • Documentation / Website
  • Improvement / Suggestion
  • Bug
  • Other (please clarify below)

Summary

src/
  artist/
    [name].js/

Should support any route like /artist/${name}/ without needing to know all the URLs up front.

Details

With this, I think we would also then be able to implement something akin to Next.js' getStaticPaths API, which could allow users to export a bunch of static content from this dynamic route definition.

export default ArtistDetailsPage extends HTMLElement {
  constructor(request) {
    super();
 
    this.request = request;
  }

  async connectedCallback() {
    const { request } = this;
    const artist = await fetch(request).then(resp => resp.json());
    const { name, bio } = artist;

    this.innerHTML = `
      <h2>${name}</h2>
      <p>${bio}</p>
    `;
  }
}

export const getStaticPaths = (async () => {
  const endpoint = 'http://www.myapi.com';
  const data =  await fetch('${endpoint}/artists').then(resp => resp.json());

  return data.map((artist) => {
    const { id, name } = artist;

    return {
      request: new Request(new URL(`${endpoint}/artists?artistId?=${id}`,
      name: `/artists/${name}/`
    }
}

With this data, Greenwood can invoke the page for as many static versions of the page the user wants using:

  • request as the "constructor prop" to pass into the page component
  • name as the output filename, based on filesystem based routing, e.g. pages/artist/[name].js

Effectively this would / could be an alternative and / or complete deprecation of the sources plugin.

@thescientist13 thescientist13 added enhancement Improve something existing (e.g. no docs, new APIs, etc) CLI SSR labels Feb 10, 2022
@thescientist13 thescientist13 added this to the 1.0 milestone Feb 10, 2022
@thescientist13 thescientist13 added feature New feature or request and removed enhancement Improve something existing (e.g. no docs, new APIs, etc) labels Mar 15, 2022
@thescientist13 thescientist13 pinned this issue Mar 27, 2022
@thescientist13 thescientist13 changed the title Serve side routes should support nested dynamic routes Server side routes should support nested dynamic routes Apr 1, 2022
@thescientist13 thescientist13 unpinned this issue May 29, 2022
@thescientist13 thescientist13 moved this from TODO to DONE in 8 - SSR Enhancements Nov 9, 2022
@thescientist13 thescientist13 moved this from DONE to DEFERRED in 8 - SSR Enhancements Nov 9, 2022
@thescientist13 thescientist13 mentioned this issue Dec 10, 2022
22 tasks
@thescientist13 thescientist13 changed the title Server side routes should support nested dynamic routes Server side routes should support nested dynamic routes with prerendering Oct 14, 2023
@thescientist13 thescientist13 changed the title Server side routes should support nested dynamic routes with prerendering Server side routes should support nested dynamic routes (with prerendering) Oct 14, 2023
@thescientist13 thescientist13 mentioned this issue Mar 9, 2024
35 tasks
@thescientist13 thescientist13 changed the title Server side routes should support nested dynamic routes (with prerendering) Server side routes should support dynamic routes (with prerendering) Apr 9, 2024
@thescientist13 thescientist13 changed the title Server side routes should support dynamic routes (with prerendering) Server side routes should support dynamic route naming (with prerendering) Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

1 participant