pages not linking
Unanswered
Beans posted this in #help-forum
BeansOP
might be a stupid question, but does anyone know why these are not linking properly? clicking on the link to project 1 just sends me to a 404.
85 Replies
@Beans might be a stupid question, but does anyone know why these are not linking properly? clicking on the link to project 1 just sends me to a 404.
Kawakawa
Are you using the app directory, or the pages directory?
@Beans might be a stupid question, but does anyone know why these are not linking properly? clicking on the link to project 1 just sends me to a 404.
Kawakawa
Go to your browser, and go to the page with the code in the first screenshot (
ProjectsPage)And tell me what the page URL is
Without clicking on any link
BeansOP
sure
Kawakawa
Yeah ok so the issue is that the link is trying to take you to localhost:3000/projects/projects/${project.slug}
(I think)
BeansOP
well but heres the 404 page
Kawakawa
Oh it's because you can't have it the way you set it up in the app dir.
BeansOP
yeah thats what happens if i remove the /projects in proejcts page functino
Kawakawa
You need to have one folder for projects, and inside of that a
page.tsx file. And then if you want a sub-route or dynamic route - make a folder for it and do the same thing.BeansOP
yeah i have that
oh
Kawakawa
Nah
BeansOP
and then another one thats like "content"
Kawakawa
You just have another file
Kawakawa
Open your projects folder, and any sub-folders and screenshot it and send it here.
BeansOP
right now its just htis
Kawakawa
Yeah that's wrong.
You should have it so that inside of projects, you have a
page.tsx file - and then a folder called [projectId] - and then inside of that folder, a file called page.tsx as wellBeansOP
ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Kawakawa
And then you can take the project ID out of the query parameters in the props of the page component
Huntaway
hello can i ask one question for a sec?
Read that @Beans
@Huntaway hello can i ask one question for a sec?
Kawakawa
Make a different thread smh
@Kawakawa Make a different thread smh
Huntaway
already done
Kawakawa
Don't ask me here then
Huntaway
wating for someone to reply@Huntaway <:fine:753870958363803719> wating for someone to reply
Kawakawa
Wait harder, you have literally been waiting 120 seconds...
@Beans Click to see attachment
Kawakawa
That's still not right, but I'm just gonna say for you to look at the docs now.
@Kawakawa That's still not right, but I'm just gonna say for you to look at the docs now.
BeansOP
fair enough, but it does seem to be working
Kawakawa
Because
You only have one route manually defined. So if e.g. you then try and go to
/projects/project2 - it will 404.You can make one page handle multiple routes with dynamic routing, though.]
@Kawakawa You only have one route manually defined. So if e.g. you then try and go to `/projects/project2` - it will 404.
BeansOP
are you sure? works with two projects also
@Beans are you sure? works with two projects also
Kawakawa
It's not gonna give you the right data, though.
Trust me.
Read the docs.
BeansOP
oh i trust you
@Kawakawa It's not gonna give you the right data, though.
BeansOP
yeah i see now
@Kawakawa You should have it so that inside of projects, you have a `page.tsx` file - and then a folder called `[projectId]` - and then inside of that folder, a file called `page.tsx` as well
BeansOP
so wouldn't it be smarter just to call it [slug]?
Kawakawa
You can put whatever you want inside of the brackets.
And then you can de-structure whatever you set it as from the page props
sorry again, but what i don't quite understand is, isnt [slug]/page.js just the same page file?
🤦â€â™‚ï¸
nvm
i think i go tit
because its dynamic it routes to whichever it matches
Kawakawa
If you have e.g.
[slug]/page.tsx, and you went to the page with the "slug" as e.g. bread - it would run the same page.tsx code as if you put cheese - it's just down to you to fetch that slug/param, and then display something different on the page based on that param/slug.Alright?
@Kawakawa If you have e.g. `[slug]/page.tsx`, and you went to the page with the "slug" as e.g. `bread` - it would run the same page.tsx code as if you put `cheese` - it's just down to you to fetch that slug/param, and then display something different on the page based on that param/slug.
BeansOP
oh i see
Kawakawa
Hold on one sec
BeansOP
no worries
Look at a past site I made for a client with Next
That'd be e.g. the parent route with the page.tsx in
And then each card just navigates to the nested dynamic route and passes the product ID as the "slug".
e.g.
https://www.theflowerhouse-burwash.co.uk/product/prod_MSj0pEMPqhdHwIAnd then I can get that in the page file props via de-structuring the props, and then I can fetch data with it and show the right content on the page.
Get it now?
@Kawakawa Get it now?
BeansOP
Sorta, your slug is a variable you use to display different info depending on it
Is how I’m understanding it
@Kawakawa And then I can get that in the page file props via de-structuring the props, and then I can fetch data with it and show the right content on the page.
BeansOP
I think this is the part I don’t understand
You’re just using one page.tsx but depending on the slug it displays different stuff?
Kawakawa
Read the docs and examples.
@Kawakawa Read the docs and examples.
BeansOP
I am, but I'm wondering if this is the best approach for what I'm trying to do
since each page is so varied, because it is a project page
but all good, i'll figure it out. thanks for the help