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

Change url from root/product/slug to root/slug #77

Closed
DivMode opened this issue Feb 2, 2022 · 4 comments
Closed

Change url from root/product/slug to root/slug #77

DivMode opened this issue Feb 2, 2022 · 4 comments

Comments

@DivMode
Copy link

DivMode commented Feb 2, 2022

Is there a simple way to move the product slug to root url?

Tried something like this but getting error and page not found.

<Link
                href={`/products/${
                  product.slug 
                  }
                as={`/${
                  product.slug 
                }`}
 >
@ndimatteo
Copy link
Owner

Hey there @DivMode you're only changing the path for links in your example code, which is not where product page routes live. This is why you are seeing a 404 error page when clicking those links, the routes simply do not exist there for products.

I'd highly recommend reading up on how dynamic routes work within Next.js

In HULL, the product routes are determined by the folder structure: /pages/products/[slug].js, while general page routes are determined by /pages/[...slug].js.

It's much easier to separate out product specific routes to their own sub-path than it is to coalesce them with the regular page routes.

I hope that helps 🤘

@DivMode
Copy link
Author

DivMode commented Feb 2, 2022

Ok from what I understand it currently isnt possible to move the products slug to root because of […slug].

Otherwise I could just move the products slug to root and it would work.

Thanks for the help, love this repo, learning a lot just from reading the code.

@ndimatteo
Copy link
Owner

Exactly. You could in theory do this, but it would require a lot more work to avoid slug collisions between regular pages and product pages, and you'd have to do additional checks to know what to render.

It's fairly standard to have products exist at a sub-path like /products (even with Shopify native) so I'd suggest sticking with the default.

Glad you're enjoying the repo! cheers 🤘

@DivMode
Copy link
Author

DivMode commented Feb 3, 2022

Actually your amazing repo has inspired me to build out a full blogging system and to start using nextjs/sanity and move away from Wordpress.

I was getting tired of Wordpress shenanigans and took some courses on react to help me get going with Nextjs and Sanity and then I came across this repo which helped me so much.

Love the whole collections and filters system which I am going to use to convert into a full blogging system with categories and tags.

I have a lot of work and learning ahead of me but am very excited for the future.

As for the reason why I wanted to the slug closer to root domain is because for SEO it is better to have the targeted keywords closer to the root domain as much as possible.

Its a small seo factor and isnt such a huge deal so Ill just stick with blog/[slug].

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

2 participants