react-router返回页面如何配置历史记录?

谁能告诉我如何返回上一页而不是特定路线?

使用此代码时:

var BackButton = React.createClass({

mixins: [Router.Navigation],

render: function() {

return (

<button

className="button icon-left"

onClick={this.navigateBack}>

Back

</button>

);

},

navigateBack: function(){

this.goBack();

}

});

此错误, ,

这是我的路线:

// Routing Components

Route = Router.Route;

RouteHandler = Router.RouteHandler;

DefaultRoute = Router.DefaultRoute;

var routes = (

<Route name="app" path="/" handler={OurSchoolsApp}>

<DefaultRoute name="home" handler={HomePage} />

<Route name="add-school" handler={AddSchoolPage} />

<Route name="calendar" handler={CalendarPage} />

<Route name="calendar-detail" path="calendar-detail/:id" handler={CalendarDetailPage} />

<Route name="info-detail" path="info-detail/:id" handler={InfoDetailPage} />

<Route name="info" handler={InfoPage} />

<Route name="news" handler={NewsListPage} />

<Route name="news-detail" path="news-detail/:id" handler={NewsDetailPage} />

<Route name="contacts" handler={ContactPage} />

<Route name="contact-detail" handler={ContactDetailPage} />

<Route name="settings" handler={SettingsPage} />

</Route>

);

Router.run(routes, function(Handler){

var mountNode = document.getElementById('app');

React.render(<Handler /> , mountNode);

});

回答:

我想你只需要通过intializing它就像你的路由器上启用BrowserHistory: <Router history={new

BrowserHistory}>

在此之前,您应该需要BrowserHistory'react-router/lib/BrowserHistory'

希望对您有所帮助!

UPDATE:ES6中的示例

const BrowserHistory = require('react-router/lib/BrowserHistory').default;

const App = React.createClass({

render: () => {

return (

<div><button onClick={BrowserHistory.goBack}>Go Back</button></div>

);

}

});

React.render((

<Router history={BrowserHistory}>

<Route path="/" component={App} />

</Router>

), document.body);

以上是 react-router返回页面如何配置历史记录? 的全部内容, 来源链接: utcz.com/qa/411545.html

回到顶部