我无法导航到它没有回应的路径路径我不知道为什么。任何人都知道我的代码有什么问题。它只是加载着陆页,而且它无法加载其他组件
import React, { Component } from "react";
import { BrowserRouter as Router, Route } from 'react-router-dom';
import Navbar from "./components/layout/Navbar";
import Footer from "./components/layout/Footer";
import Landing from "./components/layout/Landing";
import Register from "./components/auth/Register";
import Login from "./components/auth/Login";
import "./App.css";
class App extends Component {
render() {
return (
<Router>
<div className="App">
<Navbar />
<Route path="/" component={Landing} />
<div className="container">
<Route path="/register" component={Register}/>
<Route path="/login" component={Login}/>
</div>
<Footer />
</div>
</Router>
);
}
}
export default App;
答案 0 :(得分:2)
将exact
添加到初始路线,否则会被所有路径捕获,
<Route exact path="/" component={Landing} />