I'm trying to redirect urls from this format:
http://localhost:8080/setup/xyz/?code=some-code
to this:
http://localhost:8080/app/#/setup/xyz/?code=some-code
I've tried with both proxies and rewrites:
historyApiFallback: {
rewrites: [
{ from: /^\/$/, to: '/index.html' },
{ from: /^\/app/, to: '/app.html' },
{ from: /^\/setup/, to: '/app/#/setup' },
]
},
But it doesn't seem to work. Is there a way to write 301 redirects using the dev server?
@Eugen's answer put me on the right path. Here are the additional details I needed:
The current devserver API for this is onBeforeSetupMiddleware, which exposes the express server API, including redirects. For your case, I think you'd want something like:
devServer: {
onBeforeSetupMiddleware: (devServer) => {
devServer?.app?.get('/setup', (req, res) => {
res.redirect('/app/#' + req.originalUrl);
});
}
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With