diff --git a/src/components/login-form-component.jsx b/src/components/login-form-component.jsx index 3b964998..5be5f20e 100644 --- a/src/components/login-form-component.jsx +++ b/src/components/login-form-component.jsx @@ -6,19 +6,30 @@ class LoginFormComponent extends HTMLElement { super(); } + addEvent() { + const loginForm = this.querySelector("#login-form"); + + this.addEventListener("submit", (event) => { + event.preventDefault(); + + if (event.target === loginForm) { + this.handleLogin(); + } + }); + } + connectedCallback() { this.render(); } - handleLogin(event) { - event.preventDefault(); + handleLogin() { const username = this.querySelector("#username").value; if (!username) { return; } - navigateTo("/"); + navigateTo("/", { hash: window.isHash }); const user = { username, @@ -31,13 +42,13 @@ class LoginFormComponent extends HTMLElement { render() { const element = ( -