I have an <input type="text" />
as a search bar inside a <form>
.
Because it's a search bar the user should be redirected to a route similar to : /search?q=thingIWantToSearch
when the form is submited.
Currently I'm doing with a location.href
but I don't think this is a good way of doing it (or is it?)
Here's my code :
<script>
let inputValue = '';
const handleSubmit = () => {
// there should be some parsing before putting it in the url, but it's not the subject
location.href = `/search?q=${inputValue}`;
}
</script>
<form on:submit|preventDefault={handleSubmit}>
<input type="text" bind:value={inputValue} />
<button type="submit">submit</button>
</form>
So how can I properly redirect the user on form submission?
replaceState()
function. – Carrasquilloid
property tohistory.state
that increment every time something is pushed to the history. That mean areplaceState()
should manually increment theid
to keep the history intact. The issue is if sapper change his way to manage the history, it could create some unexpected bugs and force me to update every redirections. – Hilaria