Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: RouteDefinition throw redirect not working #1471

Closed
2 tasks done
0-don opened this issue May 7, 2024 · 1 comment
Closed
2 tasks done

[Bug?]: RouteDefinition throw redirect not working #1471

0-don opened this issue May 7, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@0-don
Copy link

0-don commented May 7, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 馃槸

the load method doesnt redirect to the thrown page
https://stackblitz.com/~/github.com/0-don/solid-project?file=src/routes/index.tsx

import { Title } from "@solidjs/meta";
import { RouteDefinition, redirect } from "@solidjs/router";
import Counter from "~/components/Counter";

export const route = {
  load() {
    throw redirect("/about");
  },
} satisfies RouteDefinition;

export default function Home() {
  return (
    <main>
      <Title>Hello World</Title>
      <h1>Hello world!</h1>
      <Counter />
      <p>
        Visit{" "}
        <a href="https://start.solidjs.com" target="_blank">
          start.solidjs.com
        </a>{" "}
        to learn how to build SolidStart apps.
      </p>
    </main>
  );
}

Expected behavior 馃

No response

Steps to reproduce 馃暪

No response

Context 馃敠

No response

Your environment 馃寧

No response

@0-don 0-don added the bug Something isn't working label May 7, 2024
@ryansolid
Copy link
Member

This isn't the API. redirect works within cache and action functions which are wrappers around Solid Router's data APIs. If you want to navigate inside the load function useNavigate.

It would be interesting to try to marry these together I suppose. load could have additional logic in it. But generally it isn't the load function doing the redirect as much as where the data is being used on the page.

@0-don 0-don closed this as completed May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants