Closed NetOpWibby closed 5 years ago
This is the way I am doing redirects now: https://github.com/lbryio/lbry.tech/blob/master/app/modules/redirect-404.js
Yea this is a problem we've had for a while. You can wrap the emit call inside a setTimeout(() => {}, 0)
to work around it for now
So the first instance of the redirect is here: https://github.com/lbryio/lbry.tech/blob/master/app/views/redirect.js#L51
// relevant portion
if (!fs.existsSync(`./documents/${path}.md`))
return redirect404(state, emit); // when I add emit here, it does get passed to my redirect-404.js file
// ...but replacing the HTML in that file with the code below results in nothing
setTimeout(() => {
emit("replaceState", redirectUrl);
}, 0);
Expected behavior
emit("replaceState", "/")
redirects a user to the specified URL.Actual behavior
Nothing happens. Even the official site has this issue.
Steps to reproduce behavior
Put
emit("replaceState", "/")
inside a route and be sad that you don't get redirected.I'm using fastify for the server so I'll try intercepting choo to make redirects happen via fastify instead. I'd rather do it programmatically in choo though.