好的,这是我的问题。 我正在使用反应路由器,并且交换机仅显示“ /”路由,而没有其他显示。我在开发人员工具react插件中看到了这一点。 我省略了导入语句, 我的代码App.js
const Header = () => {return (
<div>
Hello
</div>
);
}
export const App = () => {
return (
<BrowserRouter>
<div>
<Header />
<Switch>
<Route exact path="/" component={Login}/>
<Route exact path="/login" component={MainPage}/>
</Switch>
</div>
</BrowserRouter>
);}
index.js
ReactDOM.render(
<App />,
document.getElementById('root')
);
package.json
{
"name": "first-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"react": "^16.4.1",
"react-autocomplete": "^1.8.1",
"react-bootstrap": "^0.32.1",
"react-date-picker": "^6.10.4",
"react-dom": "^16.4.1",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-router-link": "^2.0.2",
"react-scripts": "1.1.4",
"react-table": "^6.8.6"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
然后反应控制台窗口中的输出 only 1 route visible, click here for my screenshot
是的,可能是这种情况,以及它在调试器中的外观。 但是,这只是问题的一部分。我还有另一个组件MainPage,它还有另一个Switch。 这在React-debugger中也是空的,当我使用按钮时,它会转到一个新页面,并且显示为空。我还要附加MainPage组件
export const MainPage = () => {
return (
<div><div>
<Navbar>
<Navbar.Header>
<Navbar.Brand>
Attendance App
</Navbar.Brand>
</Navbar.Header>
<Nav>
<NavItem eventKey='updatePage' href="showUpdatePage">
Update Attendance
</NavItem>
<NavItem eventKey='addEmployee' href="/showAddEmployeePage">
Add Employee
</NavItem>
<NavItem eventKey='reports' href="reportsPage">
Reports
</NavItem>
</Nav>
</Navbar></div><div>
<Switch>
<Route exact path='/showAddEmployeePage' component={AddEmployee} />
<Route exact path='/reportsPage' component={Reports} />
<Route exact path='/showUpdatePage' component={UpdateAttendance} />
<Route exact path='/' component={Login} />
</Switch>
</div></div>)
}