When clicking around it works fine. But when I press Command-R I get a 404. Why?
Is there something I need to setup with routes for SSR?
OK It has to do with
http://localhost:3000/my-community/
vs
http://localhost:3000/my-community
The http://localhost:3000/my-community works fine. How do I use that to make both work?
I did the following and it works:
server.get('*', (req, res) => {
// https://github.com/zeit/next.js/issues/1189
const parsedUrl = parse(req.url, true)
const { pathname, query } = parsedUrl
if (pathname.length > 1 && pathname.slice(-1) === '/') {
app.render(req, res, pathname.slice(0, -1), query)
} else {
handle(req, res, parsedUrl)
}
})
You can also use https://www.npmjs.com/package/connect-slashes if you're running express and it'll add the / at the end of your url for you. It solves a few bugs that your hand made code might not cover.
It's something that has to be handled in userland, we basically enforce without / at the end.
Most helpful comment
I did the following and it works: