Genie Discord forum

Author Avatarwerner castro
10/12/2023, 7:15:38 AM

I would like to redirect pages using a button with this function in javascript:

window.location.replace( "url", );

Author AvatarPere
10/13/2023, 6:31:03 AM

where do you want to put it? Are you writing your page in Julia or in HTML? you can add scripts with script()

Author Avatarwerner castro
10/13/2023, 2:12:42 PM

I'm using Stipple.jl. The idea would be that when you click on a button, you perform a certain validation and redirect to another page of the application. I tried with the redirect method, but I was successful.

Author Avatarwerner castro
10/13/2023, 2:13:46 PM

I thought about the solution in this script, but I don't know if it would be the best solution.

Author Avatarwerner castro
10/13/2023, 2:14:30 PM

I think about doing this redirection in the control layer.

Author AvatarPere
10/17/2023, 7:36:06 AM

Right now I can think of two ways of doing this...you do it all inside a route, like

route("/validate_and_redirect") do
    if validate()  # replace with your validation function
        redirect("/success_page")
    else
        redirect("/error_page")
    end
end

or you define a redirect function to be triggered by a button.

function ui()
    [
        btn("Redirect", @click("redirectTo('/new_path')")),
        h1("Average of random numbers"), 
        {{msg}},
        script("function redirectTo(url) { window.location.replace(url); }")
    ]
end

Another way would be to trigger the javascript redirect from the backend after validation, but I'm not sure how to go about it.