redux-bundler icon indicating copy to clipboard operation
redux-bundler copied to clipboard

navigation and enhancers

Open quarkcore opened this issue 6 years ago • 4 comments

@HenrikJoreteg hi, which kind of navigation u are unsing? i try to add react-router with react-router-redux but have some trouble.

ther for i need to add some middleware but applayMiddleware() of your package does not working as expected.

import createStore from '...';
import { applyMiddleware } from 'redux-bundler';

import { testEnhancer } from '...';

//used like that console.log in testEnhancer never logs
store = createStore({}, applyMiddleware(testEnhancer()));

any idea?

quarkcore avatar Apr 26 '18 11:04 quarkcore

Works like that! strange behavoir anyhow. why cant i pass an empty object as initial state?

import createStore from '...';
import { applyMiddleware } from 'redux-bundler';

import { testEnhancer } from '...';

store = createStore(applyMiddleware(testEnhancer()));

quarkcore avatar Apr 26 '18 11:04 quarkcore

@quarkcore you should read my book 😀 there's a whole chapter on routing. Anway... this is how I do routing:

URL bundle + Route bundle: https://github.com/HenrikJoreteg/redux-bundler-example/blob/master/src/bundles/routes.js

Then this one helper at the root of your component tree: https://github.com/HenrikJoreteg/redux-bundler-example/blob/master/src/components/layout.js#L17 this makes it so you don't need any special "link" tags or anything just render regular <a> tags and as the clicks bubble up this helper sorts out whether to treat it as internal navigation or not.

Then I use selectRoute to grab the current component based on the routes, and assign it to <Page/> and render it: https://github.com/HenrikJoreteg/redux-bundler-example/blob/master/src/components/layout.js#L13

Anywhere you need route params you can just use selectRouteParams to get an object of named route parameters or selectPathname to get current pathname, etc. The URL bundle has tons of selectors.

HenrikJoreteg avatar Apr 26 '18 15:04 HenrikJoreteg

We just hit the same issue. We have to do hash-based routing (our app may not be mounted at the root of the domain) and are trying to figure out how best to get it working with redux-bundler. We could sprinkle hash based routes all over the code, but we thought we'd try mixing it with react-router first to see if that could work. Neither approach seems ideal.

olizilla avatar May 10 '18 09:05 olizilla

We got hash based routing working the redux-bundler way by parameterising the routeInfo selector in create-route-bundle... https://github.com/HenrikJoreteg/redux-bundler/pull/23

olizilla avatar May 10 '18 10:05 olizilla