PrivateRoutes.js 920 Bytes
Newer Older
Spark's avatar
Spark committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React from 'react';
import { Redirect, Route } from 'react-router-dom';
import { isLogined } from '../utils/Auth';

function PrivateRoute({ path, children }) {
    if (isLogined()) {
        return (
            <Route path={path}>
                {children}
            </Route>
        )
    } else {
        alert('권한이 없습니다')
        return (
            <Redirect to='/' />
        )
    }
}
export default PrivateRoute

// Swal.fire({
        //     title: '권한이 없습니다.',
        //     text: ' 로그인을 진행해주세요',
        //     icon: 'warning',
        //     confirmButtonText: '확인',
        // })
        //     .then((res) => {
        //         if (res.isConfirmed) {
        //             window.location.replace('/')
        //         }
        //         else {
        //             window.location.replace('/')
        //         }
        //     })