Giter VIP home page Giter VIP logo

Comments (4)

DoctorDerek avatar DoctorDerek commented on May 23, 2024 2

Hey @koraylinux I think it's pretty straightforward to do what you want:
image
from https://nextjs.org/docs/routing/introduction#dynamic-route-segments

At least for me, it just works out-of-the-box by moving the [slug].js file from pages/posts/[slug].js to pages/[slug].js... other than updating some of the links in the rest of the code.
image

from tailwind-nextjs-starter-blog.

timlrx avatar timlrx commented on May 23, 2024

Hi, it's slightly different with nextjs since it uses file-based routing - the posts in /pages/blog/[slug] are routed to https://url/blog/slug. If you want to change it posts instead of blog, that would be relatively simple since you can move [slug].js to posts folder instead of blog but it's more tricky for it to be at the root and would need quite a bit of modification to make it work.

Alternatively, if you are porting from hugo, you can add a redirect from url/sample-page to url/blog/sample-page. The documentation covers it in detail - https://nextjs.org/docs/api-reference/next.config.js/redirects

from tailwind-nextjs-starter-blog.

expatjedi avatar expatjedi commented on May 23, 2024

The problem is that Google already indexed my old blog posts so when the visitor try to open my new site it will show 404 error. That's why i wanted to move posts in root pages directory. I will search another solution on next.js community. I hope they have a solution for this.

I also recommend you to make this modifications on your template since people who decided shifting to your theme would definitely search the same solution. Serving pages under /blog directory is not much practical.

from tailwind-nextjs-starter-blog.

timlrx avatar timlrx commented on May 23, 2024

That's what redirects do - it redirects users from the original link to the new link without 404 errors. My old blog uses the url/year/month/day/slug format and I re-directed them to url/blog/slug page for the new one so there are no such errors.

from tailwind-nextjs-starter-blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.