【发布时间】:2017-09-16 15:20:34
【问题描述】:
我的问题类似于React router appending query to URL,但我使用的是带有 Switch 和路由的反应路由器 4。在我的情况下,如何排除从历史记录中附加的额外查询参数?
render(){
return(
<div>
<Header/>
<Switch>
<Route exact path="/" render={(props) => (<Home passDealsToRoute ={this.dealsCallBack} {...props}/>)}/>
<Route exact path="/mall/:id/:store_id/:deal_id" render={(props) => (<MallDetail deals ={this.deals} {...props}/>)}/>
<Route exact path="/mall/:id/:store_id" render={(props) => (<MallDetail deals ={this.deals} {...props}/>)}/>
<Route exact path="/mall/:id" render={(props) => (<MallDetail deals ={this.deals} {...props}/>)}/>
<Route path="/home/:location" render={(props) => (<Home passDealsToRoute ={this.dealsCallBack} {...props}/>)} />
<Route exact path="/about" component={About}/>
</Switch>
<Footer/>
</div>
);}} export default withRouter(Root);
我的索引文件
import React from 'react';
import {BrowserRouter,Route} from 'react-router-dom';
import {render} from 'react-dom';
import Root from './components/root/root';
import { createBrowserHistory } from 'history';
const history = createBrowserHistory({queryKey: false});
class App extends React.Component {
render() {
return(
<BrowserRouter history={history}>
<Route path={"/"} component={Root}/>
</BrowserRouter>
);
}
};
render(<App/>,window.document.getElementById('app'));
【问题讨论】:
标签: javascript reactjs react-router react-router-v4