diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 6835c9c..728c8bc 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -6,17 +6,13 @@ import { import 'react-toastify/dist/ReactToastify.css'; import { hooks } from './providers'; -import { - MainPage, - LoginPage, - NotFoundPage, - SignupPage, -} from './pages'; +import config from './app-config'; +import pages from './pages'; -const ConditionalRoute = ({ children, redirectWhenAuthIsExist, redirectTo }) => { +const PrivateRoute = ({ children, redirectTo }) => { const auth = hooks.useAuth(); - return redirectWhenAuthIsExist === auth.loggedIn ? : children; + return auth.loggedIn ? children : ; }; const App = () => ( @@ -24,24 +20,27 @@ const App = () => (
- } /> - - - - )} - /> - - - - )} - /> - } /> + {Object + .values(config.pages) + .map(({ + id, + route, + isPrivate, + component, + }) => { + const Component = pages[component](); + return ( + + + + ) : } + /> + ); + })} diff --git a/frontend/src/app-config.js b/frontend/src/app-config.js new file mode 100644 index 0000000..1ec5a62 --- /dev/null +++ b/frontend/src/app-config.js @@ -0,0 +1,30 @@ +const pages = { + notFoundPage: { + id: 0, + route: '*', + component: 'notFoundPage', + isPrivate: false, + }, + mainPage: { + id: 1, + route: '/', + component: 'mainPage', + isPrivate: true, + }, + loginPage: { + id: 2, + route: '/login', + component: 'loginPage', + isPrivate: false, + }, + signupPage: { + id: 3, + route: '/signup', + component: 'signupPage', + isPrivate: false, + }, +}; + +export default { + pages, +}; diff --git a/frontend/src/pages/index.js b/frontend/src/pages/index.js index aeaee6e..8205be9 100644 --- a/frontend/src/pages/index.js +++ b/frontend/src/pages/index.js @@ -1,4 +1,11 @@ -export { default as LoginPage } from './LoginPage'; -export { default as MainPage } from './MainPage'; -export { default as NotFoundPage } from './NotFoundPage'; -export { default as SignupPage } from './SignupPage'; +import LoginPage from './LoginPage'; +import MainPage from './MainPage'; +import NotFoundPage from './NotFoundPage'; +import SignupPage from './SignupPage'; + +export default { + loginPage: () => LoginPage, + mainPage: () => MainPage, + notFoundPage: () => NotFoundPage, + signupPage: () => SignupPage, +};