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: Astro@0.19.1 doesn't redirect localhost:3000/ as an index file when using [...slug].astro files #1187

Closed
okikio opened this issue Aug 21, 2021 · 6 comments

Comments

@okikio
Copy link
Member

okikio commented Aug 21, 2021

What package manager are you using?

pnpm

What operating system are you using?

Linux

Describe the Bug

In #1184 I found that using Astro parameters together with [...slug].astro and getStaticPaths, with a param of index, results in only being able to access index files with a url of localhost:3000/index while localhost:3000 give an error, e.g.

---
// src/pages/[...id].astro
import { Markdown } from "astro/components";
export async function getStaticPaths() {
  return [
    { params: { id: 'index' }, props: { content: "# Hey" } },
  ];
}
const {content} = Astro.props;
---
<>
   <Markdown content={content} />
</>

I use <>...</> because of a bug in [...slug].astro files #1185

My astro config file is,

export default {
    // projectRoot: '.',     // Where to resolve all URLs relative to. Useful if you have a monorepo project.
    pages: './docs', // Path to Astro components, pages, and data
    // dist: './dist',       // When running `astro build`, path to final static output
    // public: './public',   // A folder of static files Astro will copy to the root. Useful for favicons, images, and other files that don’t need processing.
    buildOptions: {
      site: 'https://okikio.github.io/native',  // Your public domain, e.g.: https://my-site.dev/. Used to generate sitemaps and canonical URLs.
      // sitemap: true,      // Generate sitemap (set to "false" to disable)
    },
    devOptions: {
      // port: 3000,         // The port to run the dev server on.
      tailwindConfig: './tailwind.config.cjs', // Path to tailwind.config.js if used, e.g. './tailwind.config.js'
    },
    renderers: ['@astrojs/renderer-solid'],
};

Steps to Reproduce

  1. pnpm i astro@^0.19.1 @astrojs/renderer-solid@^0.1.0 -D
  2. Create an astro.config.mjs with
export default {
    // projectRoot: '.',     // Where to resolve all URLs relative to. Useful if you have a monorepo project.
    // pages: './docs', // Path to Astro components, pages, and data
    // dist: './dist',       // When running `astro build`, path to final static output
    // public: './public',   // A folder of static files Astro will copy to the root. Useful for favicons, images, and other files that don’t need processing.
    buildOptions: {
      site: 'https://okikio.github.io/native',  // Your public domain, e.g.: https://my-site.dev/. Used to generate sitemaps and canonical URLs.
      // sitemap: true,      // Generate sitemap (set to "false" to disable)
    },
    devOptions: {
      // port: 3000,         // The port to run the dev server on.
      tailwindConfig: './tailwind.config.cjs', // Path to tailwind.config.js if used, e.g. './tailwind.config.js'
    },
    renderers: ['@astrojs/renderer-solid'],
};
  1. mkdir src && cd src && mkdir pages && cd pages
  2. echo "---" > [...id].astro
    Add this to the [...id].astro file
---
// src/pages/[...id].astro
import { Markdown } from "astro/components";
export async function getStaticPaths() {
  return [
    { params: { id: 'index' }, props: { content: "# Hey" } },
  ];
}
const {content} = Astro.props;
---
<>
   <Markdown content={content} />
</>
  1. astro dev
  2. Error! I would just expect localhost:3000 to work, unfortunately I can't determine why it doesn't, however, localhost:3000/index does work

Note: you have to open http://localhost:3000 in the browser for the error to appear.

I created a CodeSanbox recreation: https://codesandbox.io/s/astro-getstaticpaths-index-redirect-grro5,
In order to clear the error you will need to add /index to the preview url, e.g. https://grro5.sse.codesandbox.io/index

Link to Minimal Reproducible Example (Optional)

No response

@okikio okikio changed the title 🐛 BUG: Astro@0.19.1 doesn't redefine index.md as an index file in [...slug].astro files 🐛 BUG: Astro@0.19.1 doesn't redirect localhost:3000/index as an index file when using [...slug].astro files Aug 21, 2021
@okikio okikio changed the title 🐛 BUG: Astro@0.19.1 doesn't redirect localhost:3000/index as an index file when using [...slug].astro files 🐛 BUG: Astro@0.19.1 doesn't redirect localhost:3000 as an index file when using [...slug].astro files Aug 21, 2021
@okikio okikio changed the title 🐛 BUG: Astro@0.19.1 doesn't redirect localhost:3000 as an index file when using [...slug].astro files 🐛 BUG: Astro@0.19.1 doesn't redirect localhost:3000/ as an index file when using [...slug].astro files Aug 21, 2021
@drwpow drwpow added help wanted Please help with this issue! and removed help wanted Please help with this issue! labels Aug 23, 2021
@drwpow
Copy link
Member

drwpow commented Aug 23, 2021

At first glance I was thinking this was in the manifest, but on second thought this might be in the dev server. Probably not a “good first issue” if the source is unclear! But I’m guessing that once the source is identified it should be straightforward.

@okikio
Copy link
Member Author

okikio commented Aug 23, 2021

Unfortunately from what I can tell this issue affects both the dev server and build time

@okikio
Copy link
Member Author

okikio commented Aug 23, 2021

Upon further inspection, this issue affect both [id].astro and [...id].astro, what happens is that astro treats each param as a folder, so, the id param creates this /index/index.html which is why the redirect doesn't work properly.
image

@FredKSchott
Copy link
Member

Thanks for the report! We believe that this has been fixed in astro v0.21, going out today. Let us know if you can still reproduce the issue after updating to v0.21 and we'll be happy to take a look.

@hayhaydz
Copy link

hayhaydz commented Nov 4, 2022

I hate to comment on something that is a year old but I can't find anyone else still having this issue. I have this exact issue when retrieving an index page from a CMS. For now a weak solution is to just use:

build: {
  format: 'file'
},

This results in a build output of /index.html instead of the default directory build option which turns into /index/index.html, if a slug or id value of 'index' is used should astro not automatically know to not build a folder for it?

It seems like maybe this was fixed and at some point has broken again?
https://codesandbox.io/s/crazy-bouman-2fi6eu?file=/src/pages/%5B...id%5D.astro

A recent version of Astro with the issue

@delucis
Copy link
Member

delucis commented Nov 4, 2022

Hi @hayhaydz! If you're seeing this with a newer Astro version, a new issue with details would be super helpful. You can link to this one for reference if you like.

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

5 participants