mirror of
https://github.com/ershisan99/flashcards-example-project.git
synced 2025-12-18 05:09:23 +00:00
lesson 3 in progress
This commit is contained in:
@@ -1,14 +1,43 @@
|
||||
import { createBrowserRouter, RouteObject, RouterProvider } from 'react-router-dom'
|
||||
import {
|
||||
createBrowserRouter,
|
||||
Navigate,
|
||||
Outlet,
|
||||
RouteObject,
|
||||
RouterProvider,
|
||||
} from 'react-router-dom'
|
||||
|
||||
const routes: RouteObject[] = [
|
||||
import { useGetDecksQuery } from '@/services/base-api'
|
||||
|
||||
const publicRoutes: RouteObject[] = [
|
||||
{
|
||||
path: '/login',
|
||||
element: <div>login</div>,
|
||||
},
|
||||
]
|
||||
|
||||
const privateRoutes: RouteObject[] = [
|
||||
{
|
||||
path: '/',
|
||||
element: <div>hello</div>,
|
||||
},
|
||||
]
|
||||
|
||||
const router = createBrowserRouter(routes)
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
element: <PrivateRoutes />,
|
||||
children: privateRoutes,
|
||||
},
|
||||
...publicRoutes,
|
||||
])
|
||||
|
||||
export const Router = () => {
|
||||
const result = useGetDecksQuery()
|
||||
|
||||
console.log(result)
|
||||
|
||||
return <RouterProvider router={router} />
|
||||
}
|
||||
function PrivateRoutes() {
|
||||
const isAuthenticated = false
|
||||
|
||||
return isAuthenticated ? <Outlet /> : <Navigate to="/login" />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user