Skip to content

Instantly share code, notes, and snippets.

@GergKllai1
Last active October 30, 2019 17:23
Show Gist options
  • Save GergKllai1/1a14a869faeeb87ba2c72bb998ee571b to your computer and use it in GitHub Desktop.
Save GergKllai1/1a14a869faeeb87ba2c72bb998ee571b to your computer and use it in GitHub Desktop.
Restricting routes with CustomRoute
import React from "react";
import { Switch } from "react-router-dom";
import CustomRoute from "./CustomRoute";
import MainIndex from "./MainIndex";
import LoginPage from "./LoginPage";
import RestrictedPage from "./RestrictedPage";
import OnlyTeacher from "./OnlyTeacher";
import OnlyStudent from "./OnlyStudent";
export const Content = () => {
return (
<>
<Switch>
<CustomRoute exact path="/index" component={MainIndex} />
<CustomRoute
condition="signedIn"
exact
path="/restricted"
component={RestrictedPage}
/>
<CustomRoute
condition="teacher"
exact
path="/only-teacher"
component={OnlyTeacher}
/>
<CustomRoute
condition="student"
exact
path="/only-student"
component={OnlyStudent}
/>
<CustomRoute exact path="/login" component={LoginPage} />
</Switch>
</>
);
};
export default Content;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment