import React from "react"; import ReactDOM from "react-dom/client"; import { createHashRouter, RouterProvider } from "react-router-dom"; import store from "./stores/index"; import { Provider } from "react-redux"; import axios from "axios"; import "./scss/index.scss"; import routes from "./routes/routes"; // 添加请求拦截器 axios.interceptors.request.use( (config) => { const myCookie = document.cookie.replace( /(?:(?:^|.*;\s*)JWT-Authorization\s*\=\s*([^;]*).*$)|^.*$/, "$1", ); if (myCookie) { config.headers["Authorization"] = `Bearer ${myCookie}`; } return config; }, (error) => { return Promise.reject(error); }, ); // 添加响应拦截器 axios.interceptors.response.use( function (response) { // 2xx 范围内的状态码都会触发该函数。 // 对响应数据做点什么 return { ...response.data }; }, function (error) { // 超出 2xx 范围的状态码都会触发该函数。 // 对响应错误做点什么 return Promise.reject(error); }, ); const router = createHashRouter(routes); const root = ReactDOM.createRoot(document.getElementById("root")); root.render( , );