import { render } from "solid-js/web";
import { action, redirect, Router, Route } from "@solidjs/router";
const isAdmin = action(async (formData: FormData) => {
console.log('running...')
await new Promise((resolve, reject) => setTimeout(resolve, 1000));
const username = formData.get("username");
if (username === "admin") throw redirect("/admin");
return new Error("Invalid username");
});
export function MyComponent() {
return (
<form action={isAdmin} method="post">
<label for="username">Username:</label>
<input type="text" name="username" />
<input type="submit" value="submit" />
</form>
);
}
function App() {
return (
<Router><Route path="*" component={MyComponent} /></Router>
);
}
render(() => <App />, document.getElementById("app")!);