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

🐛 BUG: Dynamic pages using rest parameters and generating multiple subfolders not working (404) when running dev server. #1322

Closed
jornki opened this issue Sep 5, 2021 · 3 comments

Comments

@jornki
Copy link

jornki commented Sep 5, 2021

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

Using Astro version 0.20.4

When generating a pages using rest parameters the page will fail with a 404 when running in the dev server. However, when building the project the page is correctly being generated (and works fine with preview).

Structure

/pages
/pages/subfolder/[...slug].astro

The page /pages/subfolder/[...slug].astro is generating output pages in multiple sub-levels. The date of the content for the page is being used to construct the path. For instance /subfolder/2021/09/05/name-of-page/index.html.

When running astro build the expected files will be created and everything works. However, when running the dev server all generated pages will fail with a 404.

getStaticPaths

The paths are generated to create subfolders (as seen above) using the year, month and date in this case.

export async function getStaticPaths() {
	const allPosts = await getAllPosts();
	return allPosts.map((post) => {
		const fullSlug = generateSlug(post._createdAt, post.slug.current);
                // fullSlug  example -> «/2021/09/05/the-name-of-the-post»
		return {
			params: { slug: fullSlug },
			props: { post }
		};
	});
}

Steps to Reproduce

  1. npm init astro (using Typescript)
  2. Create the structure described above
  3. Run the dev server «astro dev»
  4. Visit one of the dynamic/generated pages
  5. The page is not found.

Link to Minimal Reproducible Example (Optional)

No response

@okikio
Copy link
Member

okikio commented Sep 6, 2021

This is related to #1187

@jasikpark
Copy link
Contributor

I was able to replicate this here: https://codesandbox.io/s/astro-1322-reproduction-48dld?file=/src/pages/subfolder/%5B...slug%5D.astro

Can confirm that the HTML is built only on build, but not when using the dev server.

@tony-sull
Copy link
Contributor

Looks like this was fixed along the way post v0.21 🎉

Repro I threw together to confirm in the lastest Minimal template: https://stackblitz.com/edit/github-my7zu2?file=src/pages/blog/[...slug].astro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants