-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A declarative way to redirect #137
Comments
Hi @krishnagopinath! Thank you for your kind words! A I would personally opt for handling the redirect server-side separately, and create a custom component for the browser that does something like this, like you alluded to: <!-- Redirect.svelte -->
<script>
import { onMount } from 'svelte';
import { navigate } from 'svelte-routing';
export let to;
onMount(() => {
navigate(to);
});
</script> <!-- App.svelte -->
<Route path="/">
<Redirect to="/dashboard" />
</Route>
<Route path="/dashboard" component={Dashboard} /> |
That makes sense, @EmilTholin ! Thank you the response. Would it make sense to add this to the readme, in case of someone wanted this? Or do you think it's too trivial to be added there? Its okay if it is, was just wondering. |
I don't think a section on this in the readme will be needed now that we have this nice issue of yours that is easily searchable for anyone wanting more information about a declarative redirect. If this question were to come up more times we can add it to the readme, for sure. |
I'd second a note in the README. Minimally the keyword "redirect" and a link to this issue. While I was able to find this in a couple of minutes, there are quite a number of issues that came up when I searched "redirect" and the first thing I did was a word search the README for "redirect". |
One problem is that it will hijack the user's back button.
I would replace |
Thank you for this fantastic library!
I believe that a "declarative" way to redirect to a desired route would be very useful. Something like this: https://reacttraining.com/react-router/web/api/Redirect
Its probably very easy to implement this in user land with the
navigate
function, but it would great if the library provided a way to do that, so there aren't hundreds of implementations out there!Here's how usage would look like:
That's definitely more "declarative" than what I do now:
This is definitely more boilerplate-y than the proposed version.
I'd love to know your thoughts about this!
The text was updated successfully, but these errors were encountered: