Calling new Component({ target }) appends component to target, I want to replace all the old content of the target with the new component. How can I do that?
If you're hydrating server-rendered markup, it's better to use the hydrate: true option (docs here).
If target was previously occupied by a Svelte component, it's better to call that component's $destroy() method.
Otherwise, the simplest way is to just empty out the target element:
target.innerHTML = '';
new Component({ target });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With