Closed skywickenden closed 1 year ago
I solved this with a hack:
I used this as the route:
.add('contact-us', '/contact-us', 'reroute|/page|{"slug":"contact-us"}')
and then in server.js I added a custom handler
const handler = routes.getRequestHandler(app, ({req, res, route, query}) => {
if (route.page.substring(0, 8) === '/reroute') {
const routeParts = route.page.split('|')
app.render(req, res, routeParts[1], JSON.parse(routeParts[2]))
} else {
app.render(req, res, route.page, query)
}
})
I would be great if it was possible to send a customization object through for the custom handler so this could be less hackish. I can't be the only one who has SEO requirements that make direct url to filename conversions harder than they should be!
If this is welcome I'll put a pull request together. Essentially just a fourth parameter in the route definition that gets passed through.
I have
Which directs pages such as
/page/about-us
to/pages/page.js
with paramslug
equal toabout-us
I want to also add a route for
/contact-us
which also routes through/pages/page.js
with a slug ofcontact
. Is there a way of achieving this?