Closed edelfrade closed 6 years ago
It's more dynamic to use a pattern like /jobs/:position
and then load the cms content based on query.position
in getInitialProps
. You can send a 404 there if the position is not available in the database.
Thanks @fridays after your answer I fount this thread My only worry would be if a link remains hard-coded and someone navigates to it from the client, at that point res.statusCode wont be available so it'd return the error but with a status-code of 200, which wouldn't happen if all routes were in the routes object.
Say I've added
routes.add({name: 'job', pattern: '/:jobs/:position(pos1|pos2|pos3)', page: 'jobs'})
filling the positions from a list of available ones from a CMS, but pos2 is no longer available, other than restarting the server and changing all routes, is there a way to replace that route? maybe something like this?
routes.replace({name: 'job', pattern: '/:jobs/:position(pos1|pos3)', page: 'jobs'})
Planning on adding routes from the CMS receiving a webhook when content changes and updating the routes.