我的問題是類似於React router appending query to URL,但我使用反應路由器4與交換機和路由。在我的情況下,我怎麼能排除從歷史追加額外的查詢參數?反應路由器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'));
非常感謝。我補充道,但它仍然會在每個api調用中傳遞額外的查詢參數。 as&_ = 1505635138301。我添加了我的索引文件。 –
通過添加緩存修正true.Anyhow你的答案幫助我瞭解路由器和歷史概念的react.Thanks一噸:) –