反应很新,我正在尝试在React Router中分离登录页面,登录/注册和应用程序,但我无法使其正常工作,该页面始终加载登录页面的布局,并在其下登录。
// Imports
import 'bootstrap/scss/bootstrap.scss';
import React from 'react';
import ReactDOM from 'react-dom';
import {
BrowserRouter as Router, Route
} from 'react-router-dom';
import * as serviceWorker from './serviceWorker';
// Data
import Landing from "./components/landing/landing";
import login from './components/app/auth/login';
// App
const Root = () => (
<Router>
<Route path="/" component={Landing} />
<Route path="/login" component={login} />
</Router>
)
ReactDOM.render(
<Root />,
document.querySelector("#root")
)
// Service worker
serviceWorker.unregister();
答案 0 :(得分:3)
您必须在组件内使用exact path
。看起来像<Route exact path="/" component={Landing} />
登录页面也是如此。