Skip to content
This repository has been archived by the owner on Apr 12, 2020. It is now read-only.

Problems with redirect and condition #50

Closed
gpeto91 opened this issue Oct 29, 2019 · 3 comments
Closed

Problems with redirect and condition #50

gpeto91 opened this issue Oct 29, 2019 · 3 comments

Comments

@gpeto91
Copy link

gpeto91 commented Oct 29, 2019

Hey Guys,

I have a route like this:

<script>
    imports(...views)
    import { logged } from "./store";

    let isLogged;

    const unsubscribe = logged.subscribe(value => isLogged = value);
</script>

<Router>
    <Route path="/" redirect="/login />
    <Route path="/login" component={Login} />
    <Route path="/orders" component={Orders} condition={isLogged} redirect="/login" />
    ...
</Router>

When I access localhost:5000 I expect to be redirected to login but nothing happens. Just a blank page. Am I doing something wrong? Also, this condition (isLogged) is a variable controlled by the Svelte's store. Its value gets updated after the user login but even after it succeded and the isLogged now shows true, I can't go to localhost:5000/orders. It keeps me sending to /login.

I can't spot what I'm doing wrong. Can you guys help me on this one? Thanks!

@pateketrueke
Copy link
Contributor

pateketrueke commented Oct 30, 2019

Hmm, could you wrap isLogged in a closure? e.g. condition={() => isLogged}

According tests condition can be either a function or a boolean so it can be a reson.

@pateketrueke
Copy link
Contributor

Hi, @gpeto91 if you want you can try yrv as a drop-in replacement to svero, thank you!

@kazzkiq
Copy link
Owner

kazzkiq commented Apr 12, 2020

Svero is now deprecated. Check #68 for alternatives.

@kazzkiq kazzkiq closed this as completed Apr 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants