fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

Is there a way to remove or replace a route? #135

Closed edelfrade closed 6 years ago

edelfrade commented 6 years ago

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.

fridays commented 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.

edelfrade commented 6 years ago

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.