2016-03-04 62 views
0

我有一個單頁的應用程序。我可以使用由react-router提供的<Link>標籤來使用客戶端路由器。
<Link to='/nextRoute'>next</Link
但是,如果我需要更改點擊處理程序的路線呢? (在導航之前我有一些事情要做)如何在點擊處理程序中使用react路由器1.0.x進行客戶端路由?

使用window.location.assign將導致整個事情從服務器重新獲取,但我需要使用客戶端路由器。

回答

1

我相信1.0.x使用了history包。

你必須檢查你使用的歷史版本,但是從文檔有:

// Push a new entry onto the history stack. 
history.push('/home') 

// Replace the current entry on the history stack. 
history.replace('/profile') 

// Push a new entry with state onto the history stack. 
history.push({ 
    pathname: '/about', 
    search: '?the=search', 
    state: { some: 'state' } 
}) 

// Change just the search on an existing location. 
history.push({ ...location, search: '?the=other+search' }) 

// Go back to the previous history entry. The following 
// two lines are synonymous. 
history.go(-1) 
history.goBack() 
相關問題