supasate / connected-react-router

A Redux binding for React Router v4
MIT License
4.73k stars 593 forks source link

'search' state not getting params from url (createHashHistory) #365

Open BraMKJ opened 4 years ago

BraMKJ commented 4 years ago

I'm building a form/wizard which uses hashes to make it possible to go to different steps of the form (using url example.com/form#step-2 navigates to step 2 of the form for example). I can navigate between the steps via url and links without any issues.

However, in some cases we also want to to send params with the url to preload information in the form. When using createHashHistory the 'search' part of my state stays empty. I can get the params in 'search' when I use createBrowserHistory, but I can't use createBrowserHistory because I need the hashes for the navigation between steps.

For example when I use example.com/form?user=123456#step-2 I would expect 'search' to be '?user=123456'

const reducer = history => combineReducers({
    router: connectRouter(history),
    ...
})

export const connectHistory = createHashHistory({hashType: 'noslash'})

const store = createStore(
    reducer(connectHistory),
    {},
    composeEnhancers(
        applyMiddleware(
            routerMiddleware(connectHistory),
            thunk
        )
    )
)

export default store
ReactDOM.render(
    <Provider store={store}>
        <ConnectedRouter basename='/form' history={connectHistory}>
            <Application />
        </ConnectedRouter>
    </Provider>,
    document.getElementById("App")
);
ghost commented 4 years ago

I believe the docs explicitly state not to reference hash history, you should have no issue using hashes with browser history also. I think you just need a bit of help making it work, are you still stuck?

Tasemu commented 4 years ago

I believe the docs explicitly state not to reference hash history, you should have no issue using hashes with browser history also. I think you just need a bit of help making it work, are you still stuck?

I've been looking through the FAQ and and README, where does it state this?

Tasemu commented 4 years ago

Also, i've migrated my app to use browserHistory and am seeing the same problem as the OP has stated. Perhaps this could be an issue?

BraMKJ commented 4 years ago

I believe the docs explicitly state not to reference hash history, you should have no issue using hashes with browser history also. I think you just need a bit of help making it work, are you still stuck?

I've been looking through the FAQ and and README, where does it state this?

I can't find it either. Since starting this topic I've decided to go for a different solution alltogether, but I'm still curious as to why this didn't work.

Tasemu commented 4 years ago

I believe the docs explicitly state not to reference hash history, you should have no issue using hashes with browser history also. I think you just need a bit of help making it work, are you still stuck?

I've been looking through the FAQ and and README, where does it state this?

I can't find it either. Since starting this topic I've decided to go for a different solution alltogether, but I'm still curious as to why this didn't work.

Could you tell me what solution you're using now? my application relies on the location redux information being up to date when changing routes in order to show messages etc, this functionality no longer works due to this issue. :)