試圖在登錄成功後實現重定向。 history.pushState(null,null, '/profile')
不起作用。只需更改URL和全部。 browserHistory.push('/profile');
相同登錄後響應路由器nivagate
如何在登錄後創建重定向?
case types.LOG_IN_SUCCESS:
history.pushState(null,null, '/profile');
由於
試圖在登錄成功後實現重定向。 history.pushState(null,null, '/profile')
不起作用。只需更改URL和全部。 browserHistory.push('/profile');
相同登錄後響應路由器nivagate
如何在登錄後創建重定向?
case types.LOG_IN_SUCCESS:
history.pushState(null,null, '/profile');
由於
陣營路由器有replace
法代替transitionTo
用於重定向。 如果您有一些舊版本的路由器,則可能需要使用transitionTo
。
從Michelle Tilley檢查this。
我覺得你的情況,你可以使用(無需this
取決於你擁有的版本):
var Router = require('react-router');
Router.browserHistory.push('/somepath');
你需要調用在路由器上推法:
this.context.router.push('/profile');
萬一你在你的登錄組件中需要路由器 - 如果你添加了這個,你將擁有路由器。
LoginComponent.contextTypes = {
router: React.PropTypes.object.isRequired
};
「不起作用」是什麼意思?請明確點。 –
@Jordan,這會將URL更改爲/ profile,但不會呈現該路由中的組件。手段不會導航到新頁面 –
可能重複[自動重定向後登錄與react-router](http://stackoverflow.com/questions/29594720/automatic-redirect-after-login-with-react-router) – prosti