我正在使用react-router-dom(“^ 4.2.2”)
import React from 'react';
import ReactDOM from 'react-dom';
import AppContainer from './appContainer';
ReactDOM.render(<AppContainer />, document.getElementById('root'));
应用容器代码
import React from 'react';
import App from './App';
import { BrowserRouter, Route } from 'react-router-dom';
import { Provider } from 'react-redux';
import CascadeLocationList from
'./containers/cascadeLocation/cascadeLocationList'
import store from './store';
const AppContainer = () => (
<Provider store={store}>
<BrowserRouter>
<Route path="/" component={LocationList} />
</BrowserRouter>
</Provider>
);
导出默认AppContainer;
以下是我的路线文件
import React, { Component } from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';
import LocationList from
'./containers/Location/LocationList'
import CascadeLocationShow from
'./containers/Location/LocationShow'
export const routes = () => {
return (
<Switch>
<Route path="/" exact component={App} />
{/* location routes */}
<Route path="/fac_locations/:id" component=
{LocationShow} />
<Route path="/fac_locations" component={LocationList}
/>
</Switch>
);
};
我在app.js中错过了调用{routes()) . 我现在补充说 . 即使是现在,问题依然存在
该页面将路径视为"/"并呈现指定的组件,而不管我去的路径 . 我输入了“http://localhost:3001/fac_locations " in my url and checked the path in react console and path is " /”,呈现的组件始终是App
1 回答
我错过了在我的app.js中调用{routes())所以这就是问题,现在工作正常:)