I have problem with redirecting to other page, and resulting to this error:

I'm encountering this when I'm trying to redirect to other page in front-end script:
window.localStorage.setItem('img1', JSON.stringify({img_data}))
window.location.replace("/visitor/login");
Is there problem in setting data in localstorage then redirecting to other page?
I have a route in my server for "/visitor/login":
app.get("/visitor/login", (req, res) => {
res.render("./Visitor Module/login");
})