How to route pages on the Electron?

Asked

Viewed 79 times

0

I have an application in Electron with several HTML files and I would like to create routes in Electron as well as in Express. For example, on the home page of the application the user should log in, as in the code below:

<form action="login.html" method="get">
    <input class="data_field" type="text" name="username" placeholder="Username"/>
    <input class="data_field" type="password" name="password" placeholder="Password"/>
    <input class="button" type="submit" value="Login"/>
</form>

In this code above, the application redirects directly to the other HTML page where validations will be made and others, but that’s not what I want.

I want to send the form through a route that is not this HTML file, and with pure JS I want to capture the request, validate the information and only after that, return a new HTML file as if it were a server. How can I do this kind of thing on the Electron?

// Um código de exemplo do que eu quero fazer no Electron
electron.post("/login", (request, response) => {
    const username = request.body.username;
    const password = request.body.password;
    
    if (database[username] && database[username].password === password) {
        response.sendFile("myHTMLFile.html");
    } else {
        response.sendFile("otherFile.html");
    }
});
<form action="/login" method="post">
    <input class="data_field" type="text" name="username" placeholder="Username"/>
    <input class="data_field" type="password" name="password" placeholder="Password"/>
    <input class="button" type="submit" value="Login"/>
</form>

  • You are logging in local?

  • https://stackoverflow.com/questions/41161836/nodejs-electron-with-express

  • @Anittadeveloper yes login is done locally. I would just like to handle the requests with pure JS without having to redirect to an HTML file as I showed in the first example in the question.

  • You need to use express or html to access the database

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.