-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
param: undefined for index page is not documented #2013
Comments
I would kind of expect |
I want to fix this bug, so I want to confirm this question with you. If I set another |
@matthewp I don't think this problematic though since we can already do that by passing in |
What’s IMO? |
Sorry, edited! |
Ah, yeah so if |
Hi all! Picking this up in Docs! I know we show using The exact text we have around the examples is:
It would be great if @hayhaydz @MoustaphaDev or anyone else could weigh in on whether we need to make this line a bit more explicit, e.g.
Or maybe PR a suggestion yourself! ;) |
I do like that second version @sarah11918! I might suggest a formatting fix too: move that text to it's own dedicated paragraph to make it a little more obvious. Then we can even mix it up if we like:
|
Hey, I'm very new to this open source world so am a little out of my depth but my suggestion would be to add something like this to the code block above. Maybe also including the second line that you suggested as well. ---
export function getStaticPaths() {
return [
{params: {path: 'one/two/three'}}, // /sequences/one/two/three
{params: {path: 'four'}}, // /sequences/four
{params: {path: undefined }} // /sequences/index.html
]
}
const { path } = Astro.params;
---
... This approach on the code block needs a little work because it's a little inconsistent. i.e it'd be more consistent if they all showed an index.html file in the path, or maybe the block from right at the top of the page could be used here like so.
Or mix them both together, I'm not sure maybe you guys have some better ideas. I just think it needs to be more than a line of text. ---
export function getStaticPaths() {
return [
{params: {path: 'one/two/three'}}, // /sequences/one/two/three -> mysite.com/sequences/one/two/three/index.html
{params: {path: 'four'}}, // /sequences/four -> mysite.com/sequences/four/index.html
{params: {path: undefined }} // /sequences/four -> mysite.com/sequences/index.html
]
}
const { path } = Astro.params;
---
... |
I think this deserves an example of its own. Something like this: ---
export function getStaticPaths() {
return [
{params: {path: 'one/two/three'}},
{params: {path: 'four'}},
]
}
const { path } = Astro.params;
---
... This will generate You can also set the rest parameter to ---
export function getStaticPaths() {
return [
{params: {path: 'one/two/three'}},
{params: {path: 'four'}},
{params: {path: undefined}}, // this will create an index page at this level
]
}
const { path } = Astro.params;
---
... Now this will generate |
Somewhat related: pagination also works using this undefined value. Currently, docs only mention pagination in the form of [page].astro, but a sentence mentioning that using rest params in form of [...page].astro results in different behavior would be helpful. more details here: withastro/roadmap#385 |
It sounds like @hayhaydz, @MoustaphaDev and @veesahni all have some good ideas for content on this page! If someone is willing to pick this up in a PR and capture these ideas there to get us started, we can move this disucssion there... it doesn't have to be perfect! Once a PR is made, we can edit/refine it. I'm going to add the |
I'm closing this because I think these suggestions have been incorporated into our routing page! 🥳 Feel free reopen or create a new issue that relates to the current page in docs if you find anything! |
What version of
astro
are you using?1.6.3
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
yarn
What operating system are you using?
Mac
Describe the Bug
I've brutally copied the title of a closed issue #1187 because it seems as though it fits that issues description. The problem is that when Astro builds a
[...slug].astro
file with a slug ofindex
that is stored under the pages directory it will build as so/index/index.html
instead of the expected outcome of/index.html
, a temporary solution is to use this in the build configuration:For my particular case I'm working with a CMS and I'm retrieving all of the available pages slugs and ids but I also took the above mentioned closed issue's recreated CodeSandbox and used the latest version of Astro and could produce the same unexpected result.
Link to Minimal Reproducible Example
https://codesandbox.io/s/crazy-bouman-2fi6eu?file=/src/pages/%5B...id%5D.astro
Participation
The text was updated successfully, but these errors were encountered: