Redirect Action no working with NodeJS

Wappler Version: 3.2.2
Operating System: Windows 10

Expected behavior

I’ve created a redirect in my action steps, so user should be redirected.

Actual behavior

The user is not redirected, instead, it’s loading the page he should be redirected to

How to reproduce

In Action steps, create a condition for example and if it’s true, then add a Redirecto a new page.

I used it on a PHP based project and it was working great.
With NodeJS, it’s just loading the other page when the condition is true instead of redirecting the user.

You can see that the “index” page is loaded in my Login page in the attachement :sweat_smile:

wappler-10

How do you link to the server action?

Thanks for your answer @patrick!

I link it like that:

Server Connect component is calling the action with ajax, redirect don’t work then. You could return the url where to redirect in the result and then on success event redirect. Or make a standard link that points to the server action.

I’m not sure to 100% understand :sweat_smile:
Would you mind explaining me with more details please?

This “redirect” was working with PHP, so this is not working with NodeJS because of the Ajax, right?

From what I understand, the normal redirect functionality you are used to with PHP/ASP will not work with NodeJS.
So, the solution Patrick is suggesting is:

  1. Instead of using redirect in server action, add a set value step with output on, which returns the URL to be redirected to. EG: Name this set value to redirectURL
  2. In the server connect on page, configure the dynamic success event to do a browser.goto to the URL that was returned by the server connect. EG: dmx-on:success="browser1.goto(s_check.data.redirectURL)"
1 Like

If you have a redirect action step in a server action, then it will redirect that page when executing that step. Redirect only works when that page is loaded with the browser and not using ajax. The ajax can follow the redirect but it doesn’t update you page in the browser.

I think that you had linked it in PHP and did not call it via ajax (server connect component).

2 Likes

Thank you both @sid and @patrick
My goal was to detect if a user is already connected and redirect him/her automatically to the admin index page when he/she is trying to visit the login and register pages.
I ended up using SetValue like this and it works like a charm :grinning::

wappler-20

1 Like

Aaah! We had set it up at one place so far. And in there, we created a server action route with the redirect action. Did not understand the ajax implication at that time since did not even try that. Makes sense on how this works.