#Dynamic router for categories (posts)

7 messages · Page 1 of 1 (latest)

cursive wind
#

Hey, everybody. Can you please tell me how to make dynamic switching of posts when selecting a category? It doesn't work for me, all categories are displayed.

An example of what I have.
https://next-sanity-blog.thefubon.dev/pages

https://github.com/thefubon/next-sanity-blog/tree/main/app/(frontend)/pages

If you select a category, all posts are loaded. But I need to display only the selected category.
I'm using Sanity.io

If it's not too much trouble, please help

GitHub

Contribute to thefubon/next-sanity-blog development by creating an account on GitHub.

wide flameBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

final patio
#

could you use something like Array.filter(post => post.category === "my category" ?

#

I think we need more information about how your categories are defined

cursive wind
#

@final patio

I added a link to github and there is an example of what I did and this one doesn't work. I don't know how to do it 😦

I wanted to do the same as it is done on NextJS site

https://nextjs.org/showcase

There's a category toggle and a button to download more

I don't understand how to make categories for Next + Sanity CMS

Meet hundreds of beautiful websites powered by Next.js by Vercel

cursive wind
#

I tried this solution, as shown in the screenshot. If I specify a specific category it is displayed. Now I can't figure out how to correctly specify the value slug.current instead of 'device' so that when I click on a category on the site, it opens exactly as specified in the browser bar.

final patio
#

It looks to me like what you could do is add a useLocation hook to access the current pathname, then parse it out and use that where you currently have "device" hard-coded in your query.