'Redirecting to another page from jave-ee contoller

I have completed my email verification in java-ee and react. However after clicking the verification link which is send on email, i would like to be redirected to my react page.

This is how it wokrs:

I am sending an url on email. After clicking the verification link this contoller is called:

 @GET
    @Path("/confirmation/{token}")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response confirm(@PathParam("token") String token) throws ApplicationBaseException {
        try {
            createAccountService.confirmToken(token);
            return Response
                    .status(Response.Status.CREATED)
                    .entity("Successful registration")
                    .build();

        } catch (TokenExpiredException e) {
            return Response
                    .status(410,e.getMessage())
                    .entity("Token expired")
                    .build();
        }
    }

And i am redirected to this page:

enter image description here

Instead of this page I would like to be redirected to my custom react page. React app is running on port 3000. The url for this page is http://localhost:3000/tokenConfirmed.

I have configured my react router for this path:

 <Route path="/" element={<Layout />}>
       <Route path="/" element={<Home />} />
       <Route path="register" element={<Register />} />
       <Route path="login" element={<Login />} />
       <Route path="admin" element={<AdminPanel />} />
       <Route path="tokenConfirmed" element={<TokenConfirmationPage />} />
       <Route path="tokenExpired" element={<TokenExpiredPage />} />
 </Route>

I' ve tried adding Location header in my controller but it didn't work. I couldn't find more solutions, thats why i am writing here.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source