Skip to content

hey i wanted to suggest u one correction that will make ur applicaiton even more easier #2

@knkrn5

Description

@knkrn5

right for project routes in client u have created a protected route component and then u r loading/wrapping the protected component in this protectRoute.jsx component, but i want to sugesst u that in react-router v6 there one feature called loader, that can be used while routing the path like this
<Route path="ai-debate/:debateId" loader={authLoader} element={<DebatePage />} />

and authLoader function can use redirect from react router like this

`import { redirect } from "react-router";

export function routeGuard(type: "protected" | "auth", redirectTo?: string) {
const { user } = store.getState();

if (type === "protected" && !user.isAuthenticated)
throw redirect(redirectTo ?? "/login");

if (type === "auth" && user.isAuthenticated)
throw redirect(redirectTo ?? "/dashboard");

return null;
}

this way now u dont have to wrap any protectRoute component just add thsi loader function after the path
For more details ask AI

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions