Reactjs 如何处理错误401(未经授权)反应Laravel

Reactjs 如何处理错误401(未经授权)反应Laravel,reactjs,laravel,react-router,react-hooks,Reactjs,Laravel,React Router,React Hooks,我是react的新手,我正在做这个项目的前端,他们使用Laravel作为后端和react js作为前端,我的问题是登录过期时,我试图转到http://127.0.0.1:8000/panel而不是将我重定向到登录我收到了这个 http://127.0.0.1:8000/panel401(未经授权) 这是我的web.php Route::get('/', function () { return view('welcome'); }); Route::group(['middlewar

我是react的新手,我正在做这个项目的
前端
,他们使用
Laravel
作为
后端
react js
作为前端,我的问题是登录过期时,我试图转到
http://127.0.0.1:8000/panel
而不是将我重定向到
登录
我收到了这个

  • http://127.0.0.1:8000/panel
    401(未经授权)
这是我的
web.php

Route::get('/', function () {
    return view('welcome');
});
Route::group(['middleware' => ['auth:web-charity,web']], function () {
    Route::view('/{path?}', 'welcome');
});
welcome.blade.php
中,我像这样加载我的
app.js

<!DOCTYPE html>
    <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <title>Hi</title>
        </head>

    <body>
        <div id="app"/>
        <script src="js/app.js" defer></script>
    </body>
</html>
最后,
:)
索引.js

import ReactDOM from 'react-dom';
import Index from './components/index';
import { BrowserRouter } from 'react-router-dom'

if (document.getElementById('app')) {
    ReactDOM.render(
        <BrowserRouter>
            <Index />
        </BrowserRouter>
        , document.getElementById('app'));
}
function Index() {
    return (
        <Router >
            <Switch >
                <Route path="/panel" component={Panel} />
                <Route path="/" exact component={Login} />
            <Switch/>
        <Router/>
    )
}
export default Index;
函数索引(){
返回(
)
}
出口违约指数;