I am currently working on a next.js
application. The issue i am facing is with next/link
. Link works well if i am navigating through the application. Every page is rendered properly. The problem shows up when i refresh a page and the URL ends with a slash.
http://localhost:3000/about/
The above route is showing "Page not found" while the following route will load the page successfully.
http://localhost:3000/about
I am using link
as follow:
<Link href="/about">
<a>About</a>
</Link>
Any help will be appreciated. Thanks.
I hope there should be an easiest way to do that. However you can do this using custom server . Here is an example:-
server.get("/about/", (req, res) => {
return app.render(req, res, "/about")
})
I worked around this issue by switching out the tags for a simple tag. Not ideal but at least it prevented the default handling of the trailling slash by nextjs.
<a href="/about">About</a>
In my case I was directing to a page where I had no control over the url format.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.