Comments (11)
Stay tuned, I'm including a real fix for this in the next major version π
from redux-little-router.
Within Link.js is the handleClick method that dispatches the constants of action-types. The following works for me on different routes.
dispatch({
type: 'ROUTER_PUSH',
payload: '/about'
});
from redux-little-router.
Dear @tptee, have you deployed the real fix yet? Thanks in advance.
from redux-little-router.
I'm also interested in this fix! Just ran into this same issue and am about to start dispatching 'PUSH' actions, but it'd be great if there were an official way to handle this case.
from redux-little-router.
I pulled much of the functions of <Link />
component into separate utility file.
https://gist.github.com/ngbrown/d1874f93beebc3e6724217f88cc2d295
The only real complication is that the containing component needs to reference the router
from context
.
You use it like this:
import React from "react";
import {Navbar, Nav, NavItem, FormGroup, FormControl} from "react-bootstrap";
import {handleClickNav, handleOnSubmitNav} from "./utilities.js";
export default function AppNavbar(props, context) {
const {router} = context;
return (
<Navbar>
<Navbar.Form pullLeft>
<form action="/search" onSubmit={handleOnSubmitNav(router, "/search")}>
<FormGroup>
<FormControl type="text" placeholder="Search" name="q" />
</FormGroup>
</form>
</Navbar.Form>
<Nav>
<NavItem href="/items" onClick={handleClickNav(router, "/items")}>View Items</NavItem>
</Nav>
</Navbar>
);
}
AppNavbar.contextTypes = {
router: React.PropTypes.object
};
I think that these utility functions should become part of the normal redux-little-router
API. See the gist for a start. Branch and improve it if you have any suggestions.
This should also work with universal, server-rendered, output where the client doesn't have JavaScript enabled.
from redux-little-router.
Hey all, I totally overlooked closing this issueβv13
and higher have official navigation action creators: https://github.com/FormidableLabs/redux-little-router#provided-actions-and-state
from redux-little-router.
Hey there! Right now there's a bug in the store enhancer that prevents dispatching router events within middleware (#36), so I'm not encouraging this use case until that's fixed (should be soon). If you look at the Link
source, you can see an example of where we dispatch PUSH
or REPLACE
events. These do currently work when dispatch
ing from React components or async action creators.
Here's an issue tracking the documentation of these actions, blocked by #36: #44
I'm hoping to fix this bug and give you a real answer soon! π
from redux-little-router.
Really hope this could be fixed soon. Meanwhile, I hacked this by dispatching 'ROUTE_LOCATION_CHANGED' with manually generated payload.
from redux-little-router.
Still kind of lost on this one. I've seen the ROUTE_LOCATION_CHANGED
action creator and type, but I'm unsure as to whether I'm supposed to use that to trigger a page transition (like a 'redirect' after successful login)
from redux-little-router.
As a beginner, here was the bare minimum I needed to get a react-bootstrap Nav component working with the router. If you need more complex URL routing, please consider the above post. Something like these examples would be a nice addition to the docs. :-)
import React from 'react';
import {connect} from 'react-redux';
import Nav from 'react-bootstrap/lib/Nav';
import NavItem from 'react-bootstrap/lib/NavItem';
import {PUSH} from 'redux-little-router';
const NavRouter = ({dispatch}) => {
const handleSelect = selectedKey => {
dispatch({ type: PUSH, payload: { pathname: selectedKey /* OPTIONAL , query: {search: 'cats'} */ } })
}
return (
<div>
<Nav bsStyle="pills" onSelect={handleSelect}>
<NavItem eventKey={'/page1'} href="/page1">Page1</NavItem>
<NavItem eventKey={'/page2'} href="/page2">Page2</NavItem>
</Nav>
</div>
);
};
export default connect()(NavRouter); // empty connect() passes component the {dispatch} function
from redux-little-router.
@BigBuckBunny thanks for the temporary fix. Would be really great if this could be included soon or at least documented. I think this is one of the main advantages of this library over react-router
.
from redux-little-router.
Related Issues (20)
- Warning in build with 14.3 HOT 1
- [MAJOR] Move `immutable/*` re-exports to `immutable/index.js` HOT 1
- Examples give flow errors, (Flowtypes incorrect?) HOT 1
- No underscores in query params. HOT 1
- Trouble using authentication
- Parameter basename in function routerForBrowser does not work if it ends with a slash HOT 1
- There is not enough information in the README HOT 1
- Publish TypeScript types along with package? HOT 4
- Routes ending in a slash are broken
- Infra: Automatically verify index.d.ts HOT 1
- How to test (context troubles) HOT 1
- Link's active state is super opinionated HOT 1
- How to match child route and parent sibling <Fragment>s simultaneously HOT 2
- Missing pathname Flow annotation
- TypeScript: Redundant confliting definition of History interface HOT 3
- Hot module reloading causes issues? HOT 1
- Url changes, but component doesn't change on push. Correct component shows up on refresh with correct url. HOT 1
- Hash router?
- How to render an overlay on top of main content (2 fragments at once)? HOT 2
- Support redux v4 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-little-router.