On a 404 error, I don't want to display a 404 page. Instead, I'd like to redirect back to the index page if the user is logged in or to the login page if the user is logged out. I'm already able to route the user to the login in page from the index page if not signed in, so I may just need to redirect to the index page and have it take care of the reroute to the login in page, although that seems inefficient to have to do two reroutes.
I'm able to accomplish it by re-writing the routes/_error.svelte
page to this...
<script>
import { onMount } from 'svelte';
onMount(() => {window.location.href = '/'});
</script>
But I'm not very confident it's the best way to accomplish what I want to do. It also redirects for all errors, and in a future project, I may want to show certain errors such as 404, but redirect on other errors like 500.
Does anyone have some insight on how this might be better accomplished using Sapper?
error
object and the HTTPstatus
are made available to the_error.svelte
template. So you could choose to redirect only ifstatus === 404
, for instance, and display various content for other status codes. Reference here: sapper.svelte.dev/docs#Error_page – Neckwear_error.svelte
template using theonMount
method, or is there a different way for it to be accomplished on the server end? – Olcott_error.js
server route instead of the_error.svelte
client route? Haven't tried it, but it might be worth investigating. – Neckwear