react-router-redux

React Router 4.x - PrivateRoute not working after connecting to Redux

不打扰是莪最后的温柔 提交于 2019-11-30 00:35:06
PrivateRoute available in Example https://reacttraining.com/react-router/web/example/auth-workflow is not working after connecting with Redux. My PrivateRoute look almost same to the original version but only connected to Redux and used it instead of fakeAuth in the original example. const PrivateRoute = ({ component: Component, auth, ...rest }) => ( <Route {...rest} render={props => auth.isAuthenticated ? <Component {...props} /> : <Redirect to={{ pathname: "/login" }} />} /> ); PrivateRoute.propTypes = { auth: PropTypes.object.isRequired, component: PropTypes.func.isRequired } const

React Router work on reload, but not when clicking on a link

我们两清 提交于 2019-11-28 06:54:49
I have setup the React with react-router version 4. The routing works when I enter the URL directly on the browser, however when I click on the link, the URL changes on the browser (e.g http://localhost:8080/categories ), but the content don't get updated (But if I do a refresh, it gets updated). Below is my setup: The Routes.js setup as follows: import { Switch, Route } from 'react-router-dom'; import React from 'react'; // Components import Categories from './containers/videos/Categories'; import Videos from './containers/videos/Videos'; import Home from './components/Home'; const routes = (

react-router scroll to top on every transition

风流意气都作罢 提交于 2019-11-27 18:18:36
I have an issue when navigating into another page, its position will remain like the page before. So it wont scroll to top automatically. I've also tried to use window.scrollTo(0, 0) on onChange router. I've also used scrollBehavior to fix this issue but it didnt work. Any suggestion about this? The documentation for React Router v4 contains code samples for scroll restoration. Here is their first code sample, which serves as a site-wide solution for “scroll to the top” when a page is navigated to: class ScrollToTop extends Component { componentDidUpdate(prevProps) { if (this.props.location !=

getting 404 for links with create-react-app deployed to github pages

夙愿已清 提交于 2019-11-27 16:40:23
问题 I'm trying to deploy a create-react-app to a relative path on GitHub pages with a custom domain. E.g. www.example.com/myproject I'm using react-router-dom , react-router-redux and react-router-bootstrap I've set homepage to http://www.example.com/myproject in packages.json (tried homepage = "." too) and also configured basename for my history: ... export const history = createHistory({ basename: '/myproject' }); const middleware = [thunk, routerMiddleware(history)]; ... const

Detect Route Change with react-router

断了今生、忘了曾经 提交于 2019-11-27 11:07:10
I have to implement some business logic depending on browsing history. What I want to do is something like this: reactRouter.onUrlChange(url => { this.history.push(url); }); Is there any way to receive a callback from react-router when the URL gets updated? You can make use of history.listen() function when trying to detect the route change. Considering you are using react-router v4 , wrap your component with withRouter HOC to get access to the history prop. history.listen() returns an unlisten function. You'd use this to unregister from listening. You can configure your routes like index.js

How to sync Redux state and url hash tag params

做~自己de王妃 提交于 2019-11-27 10:02:45
We have a list of lectures and chapters where the user can select and deselect them. The two lists are stored in a redux store. Now we want to keep a representation of selected lecture slugs and chapter slugs in the hash tag of the url and any changes to the url should change the store too (two-way-syncing). What would be the best solution using react-router or even react-router-redux ? We couldn't really find some good examples where the react router is only used to maintain the hash tag of an url and also only updates one component. Thanks!!! Dan Abramov I think you don’t need to. (Sorry for

Deploying react-redux app in AWS S3

不羁岁月 提交于 2019-11-27 07:42:47
I have gone through lot of similar questions in stack overflow like this one . Each one have different perspective of deploying the react app. But this question is for those who use redux , react-router and react-router-redux . It took me lot of time to figure out the proper ways to host Single page application. I am aggregating all the steps here. I have written the below answer that contains the steps to deploy react-redux app to S3. There is a video tutorial for deploying react app to s3. This will be easy for deploying the app as such on s3 but we need to do some changes in our react app.

React Router work on reload, but not when clicking on a link

北战南征 提交于 2019-11-26 22:54:05
问题 I have setup the React with react-router version 4. The routing works when I enter the URL directly on the browser, however when I click on the link, the URL changes on the browser (e.g http://localhost:8080/categories), but the content don't get updated (But if I do a refresh, it gets updated). Below is my setup: The Routes.js setup as follows: import { Switch, Route } from 'react-router-dom'; import React from 'react'; // Components import Categories from './containers/videos/Categories';

React-Router External link

左心房为你撑大大i 提交于 2019-11-26 19:50:29
Since I'm using react-router to handle my routes in a react app, I'm curious if there is a way to redirect to an external resource. Say someone hits: example.com/privacy-policy I would like it to redirect to: example.zendesk.com/hc/en-us/articles/123456789-Privacy-Policies I'm finding exactly zero help in avoiding writing it in plain JS at my index.html loading with something like: if ( window.location.path === "privacy-policy" ){ window.location = "example.zendesk.com/hc/en-us/articles/123456789-Privacy-Policies" } Evgeny Lukianchikov Here's a one-liner for using React Router to redirect to

How to sync Redux state and url hash tag params

血红的双手。 提交于 2019-11-26 14:59:40
问题 We have a list of lectures and chapters where the user can select and deselect them. The two lists are stored in a redux store. Now we want to keep a representation of selected lecture slugs and chapter slugs in the hash tag of the url and any changes to the url should change the store too (two-way-syncing). What would be the best solution using react-router or even react-router-redux? We couldn't really find some good examples where the react router is only used to maintain the hash tag of