我使用 React Router 和 Laravel。當我瀏覽 Link 元素時一切正常,但是當我更改瀏覽器地址行以手動顯示另一個組件時,Laravel 顯示它默認的 404 頁面。這是默認的 web.php 內(nèi)容,在welcome.blade.php 中我包含 js/app.js 文件:Route::get('/', function () {
return view('welcome');
});這是我的 App.js 內(nèi)容:import React from 'react';import { Switch, Route } from "react-router-dom";import Signin from "../../containers/Signin";import Signup from "../../containers/Signup";import Error from "../../containers/Error";import Courses from "../../containers/Courses";import Course from "../../containers/Course";import Quiz from "../../containers/Quiz";import Header from "../Header";import "./App.css";import Library from "../../containers/Library";import QuizResults from "../../containers/QuizResults";import Main from "../Main";import StudentsList from "../../containers/StudentsList";function App(){ return ( <div className="App"> <Header isLogged={false}/> <Switch> <Route exact path='/' component={Signin} /> <Route path='/signup' component={Signup} /> <Main> <Route path='/courses' component={Courses} /> <Route path='/course/:id' component={Course} exact/> <Route path='/quiz' component={Quiz} /> <Route path='/library' component={Library} /> <Route path='/quiz-results' component={QuizResults} /> <Route path='/students' component={StudentsList} /> </Main> <Route component={Error} /> </Switch> </div> );}export default App;應(yīng)用程序.js:import React from 'react';import ReactDOM from 'react-dom';import { BrowserRouter } from 'react-router-dom';import App from './components/App';import './index.css';ReactDOM.render( <React.StrictMode> <BrowserRouter> <App /> </BrowserRouter> </React.StrictMode>, document.getElementById('root'));那么,如何強制 React Router 對直接瀏覽器地址行更改做出反應(yīng)?
React Router 無法識別 Laravel 中的直接地址行更改
UYOU
2023-07-06 16:40:34