2017-02-24 41 views
5

: "^ 3.0.2",sayfa yeniden yüklemede tepki-yönlendirici nasıl sıfırlanacağını "tepki-yönlendirici" kullanılarak

Ben şu anda varsayılan görünümü, gitmek için gereken bir sayfa yeniden yapmanız zaman yapıyor. Ancak, tarihteki asıl rota hala yenileme yaptığım yer ile aynı. Öyleyse, bu bileşen olmaması gerektiğinde yeniden monte edilir. Bu benim kullanıcı hala geçerli bir oturum belirteci olup olmadığını görmek için kontrol edin ve nasıl kontrol paneline yeniden yönlendirmek nasıl

yönlendirme geçmişi

export const browserHistory = useRouterHistory(useBeforeUnload(createHistory))() 

yolları

<Router history={browserHistory}> 
    <Route path='/' name='Auth' component={Auth}> 
     <IndexRoute 
     component={Dashboard} 
     onEnter={(nextState, replace) => replace('/login')} /> 
     <Route path='dashboard' name='Dashboard' component={Dashboard} /> 
     <Route path='resources' name='Resources' component={Resources} /> 
     <Route path='users' name='Users' component={UsersContainer} /> 
     <Route path='user/:params' name='User' component={UserContainer} /> 
    </Route> 
    <Route path='/' name='NoAuth' component={NoAuth}> 
     <Route path='login' name='Login Page' component={Login} /> 
    </Route> 
    </Router> 

. Bunu en iyi şekilde yapıyorum emin değilim. Eğer yığının üstüne başka bir rota itmek .push yöntemi kullanabilirsiniz tepki-router ile yeni bir rota üzerine itmek isterseniz sizi buysa

const _checkAuth =() => { 
    if (profile) { 
    const res = JSON.parse(profile) 
    store.dispatch({ type: types.LOGIN_IDENTITY_SUCCESS, res }) 
    console.log(browserHistory.getCurrentLocation().pathname) 
    router.replace('/dashboard') 
    } 
} 

_checkAuth() 

cevap

3

, bu tarihte ilk rotayı kaldırılmayacak arayan, ancak doğru browserHistory.push('/dashboard')

ile

const _checkAuth =() => { 
    if (profile) { 
    const res = JSON.parse(profile) 
    store.dispatch({ type: types.LOGIN_IDENTITY_SUCCESS, res }) 
    console.log(browserHistory.getCurrentLocation().pathname) 
    browserHistory.push('/dashboard'); 
    } 
} 

_checkAuth() 

Sadece router.replace('/dashboard') yerine tepki-yönlendirici içine yeni bir rota itecektir

İlgili konular