Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

reactjs - Add pages to dynamic routes on runtime Next Js

So I am working on a simple next js application A Blog System. So like a basic blog, I have a posts section where I see all my posts that i have ever posted.

The post page is a dynamic route named

/posts/title-of-the-post   

So i used a getStaticPaths and getStaticProps for extracting the title and fetching the data from the mongodb database. It is all working great.

But I have another route called

/posts/add-new

that adds a new post to my database and my readers can see these. So the function is working and when I create a new post it is saved in the database but when I try to access it with url of posts/new-post-url I get 404 Not Found error.

I can pretty much understand that the dynamic pages and paths are build on runtime so when I add a new page, it is not in the build folder so 404.

But how to solve it. What I want is the ability to add new pages in my blog and they should be SEO friendly and visible to user. Just like how I posted this question on stack overflow and it will now be accessible by the url and after some time it will take the top spot in google search.

Please help. Thank YOu in advance :( -> :| -> :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...