2017-02-06 52 views
0

試圖在登錄成功後實現重定向。 history.pushState(null,null, '/profile')不起作用。只需更改URL和全部。 browserHistory.push('/profile');相同登錄後響應路由器nivagate

如何在登錄後創建重定向?

 case types.LOG_IN_SUCCESS: 
     history.pushState(null,null, '/profile'); 

由於

+1

「不起作用」是什麼意思?請明確點。 –

+0

@Jordan,這會將URL更改爲/ profile,但不會呈現該路由中的組件。手段不會導航到新頁面 –

+0

可能重複[自動重定向後登錄與react-router](http://stackoverflow.com/questions/29594720/automatic-redirect-after-login-with-react-router) – prosti

回答

0

陣營路由器有replace法代替transitionTo用於重定向。 如果您有一些舊版本的路由器,則可能需要使用transitionTo

從Michelle Tilley檢查this


我覺得你的情況,你可以使用(無需this取決於你擁有的版本):

var Router = require('react-router'); 
Router.browserHistory.push('/somepath'); 
0

你需要調用在路由器上推法:

this.context.router.push('/profile'); 

萬一你在你的登錄組件中需要路由器 - 如果你添加了這個,你將擁有路由器。

LoginComponent.contextTypes = { 
    router: React.PropTypes.object.isRequired 
};