Adding a base URL to an app using Redux-Router + React-Router

后端 未结 4 1564
孤独总比滥情好
孤独总比滥情好 2020-12-29 08:35

I\'m using React-Router 1.0.0-rc3 together with Redux-Router 1.0.0-beta3.

When using React-Router, you can use useBasename with createHistory

4条回答
  •  不思量自难忘°
    2020-12-29 09:13

    For react-router v2 or v3 and using react-router-redux v4 instead of redux-router, the setup of the history object will look like this:

    import { createHistory } from 'history'
    import { useRouterHistory } from 'react-router'
    import { syncHistoryWithStore } from 'react-router-redux'
    
    const browserHistory = useRouterHistory(createHistory)({
      basename: ''
    })
    const history = syncHistoryWithStore(browserHistory, store)
    

    The rest of the setup is as usual when there is no extra base URL.

提交回复
热议问题