Sha256: 68ef5c93b7d1911cda614ccedf2f994f4627fe028f43340e19b78d0d993ac922

Contents?: true

Size: 954 Bytes

Versions: 6

Compression:

Stored size: 954 Bytes

Contents

import Home from '@/pages/home'
import SignIn from '@/pages/sign-in'
import { Navigate, Outlet, createBrowserRouter } from 'react-router-dom'
import { useSelector } from 'react-redux'
import { validateCurrentUser } from '@/store/slices/userSlice'
import { store } from '@/store'
import MainLayout from '@/layouts/main-layout'

const PrivateRoute = () => {
  const user = useSelector(state => state.user)
  console.log(user)
  return (
    user.isLogged ? <MainLayout><Outlet /></MainLayout> : <Navigate to='/sign_in' />
  )
}

const router = createBrowserRouter([
  {
    element: <PrivateRoute />,
    loader: () => {
      return store.dispatch(validateCurrentUser())
    },
    children: [
      {
        path: '/',
        element: <Home />,
        exact: true
      },
      {
        path: '/home',
        element: <Home />,
        exact: true
      }
    ]
  },
  {
    path: '/sign_in',
    element: <SignIn />

  }
])

export default router

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
flamerb-0.3.0 templates/frontend/router/index.jsx
flamerb-0.2.3 templates/frontend/router/index.jsx
flamerb-0.2.0 templates/frontend/router/index.jsx
flamerb-0.1.3 templates/frontend/router/index.jsx
flamerb-0.1.2 templates/frontend/router/index.jsx
flamerb-0.1.1 templates/frontend/router/index.jsx