-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the recommended way to integrate with redux-simple-router #1
Comments
Ok, apparently |
Hey @yakirn If you could take the time and add a Wiki page that would be great. I will link it from the README then. |
I would be very happy to have a wiki for this ! I'm litteraly stuck with the router |
Alright, I will see what I can do in the next couple of days. |
Many thanks ! |
Added routing with |
Nice ! But how to render a component with a specific route ? I see that all routes are loading the App container. |
No, you can make another container and simply route to that. Maybe I'll do a short writeup of a Demo application... |
I thought that the interest of the App container was to be the main container. |
And I feel that having separate containers from App means that I will have to manually populate them when I create actions/reducers while the generator do this for me with App container. |
Yeah, well routing highly depends on your application and what you want to accomplish. About the structure: I would put all static things like header and footer to I am putting all this into a small demo right now, so stay tuned, should be done in the next couple of hours. |
So, here we go I added a wiki page to explain the setup of a simple counter app. |
I see that you implementend the container generator ? (I mean that you should update the readme) |
Yes I updated it in the development branch, just did not merge it into master yet. The action is triggered somewhere, either in the container or from within a component. I use containers in such a way that they handle which Props are passed to the components lying beneath. The components are dumb, they do not care about anything else, than that they get all the props they need - so absolutely no business logic is in containers - they show (parts) of the state and they trigger actions. What I mean by that is, that I rarely use more than one container, so when I do, it surely has to have mayor differences to the App container, so I am not sure how much sense it makes to generate a new container with all the same functionality as the App container. |
Added information to Wiki, closing now. |
(referring to the wiki page) How do you adapt the |
I suggest using the way described in the Wiki. Your outer most container is responsible for routing and provides all the routes. The route component itself is just a component distributing the props to the real components beneath it. Not sure if I understand your question regarding multiple routes. In the example in the Wiki I handle three routes:
or do you mean nested routes like /foo/bar/:someId ? I guess I should really work on a routing example. |
/foo and /bar are both using the If you check my linked issue, you'll notice that @stylesuxx mentions
|
Yes, that was me replying ;-) I will try to set up an example in the next couple of days to illustrate this. |
ahhhhhhhhh I was using email on my phone. Thanks! |
This is just a short log of my experimentation with react-router, skip to the bottom for source link. Abstract:In this example the user will be shown a link to the login page if not logged in yet. After the user is logged in, a link to the member area will be displayed. The user will be greeted on the member page after logging in. Used routes:
Base Setup
ActionsThis example will only need one action to switch the logged in state of the user.
ReducersOnly a single state needs to be tracked and this is the users logged in state:
Simply add a boolen flag to the reducer to keep track of the login state. Also set up the action so that the login state is set to true if a login action happens. ComponentsWe will use the following components:
ContainersFor our routes we will need wrapper containers to connect to the stores and set up actions:
RoutesInstall react-router
Routes are set up in Main.js So you basically need a container for every route which you need to connect to the store and set up your actions and props for this route. As far as I can see you will not get around copy and pasting all the actions and props you need for your routes, aka connecting the container to the store. I was under the impression one could pass props to the routes directly, this does not seem to be the case, I must have confused it with the URL params. Please let me know if this makes sense to you, or if you can think of a better way. I will experiment with other routers and will add this findings to the Wiki. Maybe I adapt the example and merge it to master for future reference. You can find the whole source here => https://github.com/stylesuxx/generator-react-webpack-redux/tree/feature/routing-example/examples/routing |
@stylesuxx Wow, thanks! I'm a bit relieved that's the only option I have, as I've already scaffolded my entire project like so. |
I would not say it is the only way (especially in the JS universe ;-), there are multiple routing solutions:
I have not evaluated all of them, universal-router looks very promising, since it seems to allow to simply pass props down to route components. On the other hand, react-router-redux might be the way to go in order to keep time travel functionality. I would really like to see a generator for routes. I just do not want to rush it, first evaluate which solution would be the best fit. If you have any input on one of the mentioned libraries, feel free to share your experience. |
I created a clean project using the generator.
then,
npm install --save react-router redux-simple-router
but couldn't render components using Routes.
I changed run.js to render the routes:
Modified reducers/index.js to combine the routeReducer:
and added
Router.RouteHandler
to render under Main.js (AppComponent).but I keep getting these two errors:
Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of
AppComponent
.Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of
AppComponent
.Thanks in advanced
The text was updated successfully, but these errors were encountered: