react-router-v4

Proper way of handling conditional component render depending on route?

一曲冷凌霜 提交于 2019-12-07 03:04:19
问题 I searched a lot on the Web and SO, asked in reactiflux chat, but didn't found a clean and non-hack-looking way of rendering some component depending of route/path. Let's say I have the <Header /> which should be shown on some pages and should be hidden on other ones. For sure I can use this string in Header component if (props.location.pathname.indexOf('/pageWithoutAHeader') > -1) return null That's totally fine, if /pageWithoutAHeader is the unique. If I need same functionality for 5 pages

react-router v4 nesting routing issue

ⅰ亾dé卋堺 提交于 2019-12-06 16:47:06
I have a following situation: <Wrapper> <Container> <Route exact path="/" component={UserListing} /> <Route path="/user/:id" component={UserDetails} /> <Route exact path="(/|/user/\d+)" component={StaticComponent} /> </Container> <Route path="/create-account" component={CreateAccount}/> </Wrapper> Okey, so my case is simple: I don't want the Container component to render if path does not equal to "/" or "/user/:id" . So if path is "/create-account" only Wrapper with CreateAccount as child should appear, without Container . Looking for some help. Thank you You can write a custom component that

How to navigate to a new page react router v4

℡╲_俬逩灬. 提交于 2019-12-06 13:08:10
问题 I'm building a crypto currency market app as an to practice reactjs. When app starts list of currencies with some properties will be shown as a list. I need to navigate to a different page (new page - Currency component) without loading the component on the bottom of current page. At the moment I was able to render it in the bottom of the page. But that's not what I need. Is there any other way than which is mentioned in Route to different page[react-router v4] ? Because I need to pass the

How to preload data with react-router v4?

ⅰ亾dé卋堺 提交于 2019-12-06 09:29:07
问题 This is example from official docs (https://reacttraining.com/react-router/web/guides/server-rendering/data-loading): import { matchPath } from 'react-router-dom' // inside a request const promises = [] // use `some` to imitate `<Switch>` behavior of selecting only // the first to match routes.some(route => { // use `matchPath` here const match = matchPath(req.url, route) if (match) promises.push(route.loadData(match)) return match }) Promise.all(promises).then(data => { // do something w/

using React router with Next JS route

a 夏天 提交于 2019-12-06 08:42:37
问题 i have simple question , i am new in Next.JS we have a project and my web application manage routes in BackEnd with Next JS now my problem is here , i want use React-Router-dom in one section forexample before im working with Laravel and React in Laravel I set My Route like This Route::get('/reactPage/*' ...) and then use Clien route with react but i dont know how handle this with Next JS ( more details => for example i want user click to some link after that user see a page with some link

How to make path param to be optional in react router dom(v4)?

瘦欲@ 提交于 2019-12-06 07:32:15
This is my code which I don't think is right and redundant: <BrowserRouter> <Route exact={true} path="/" component={App}/> <Route path="/:filter" component={App}/> </BrowserRouter> I think exact={true} is redundant since I can simply do path="/(:filter)" in previous react router versions? I don't wanna use history.push :( This is how I usd my NavLink in my Footer Component: const Footer = () => ( <p> Show: {" "} <FilterLink filter="all"> All </FilterLink> {", "} <FilterLink filter="active"> Active </FilterLink> {", "} <FilterLink filter="completed"> Completed </FilterLink> </p> ); and my

How preserve query string and hash fragment, in React-Router 4 <Switch><Redirect>?

我的未来我决定 提交于 2019-12-06 04:57:25
If you have a <Redirect> inside a <Route> , you'll get a location and can do: <Redirect search={props.location.search} hash={props.location.hash} ... . However, when directly inside a top level <Switch> , the <Redirect> doesn't have any props.location to access search and hash on. Is there no way to preserve the query string and hash fragment, in a <Redirect> directly after a top level <Switch> (no <Route> higher up in the tree)? Example: (Typescript) Router({}, Switch({}, Redirect({ path: '/', to: '/latest', exact: true })))) Changing to: '/latest' to to: { pathname:... search:.. hash:.. }

React Router: Query Param Match?

99封情书 提交于 2019-12-06 03:19:30
问题 According to the accepted answer to this question, React Router 4 doesn't match query parameters anymore. If I go from a URL matched by one of my <Route> s to the same URL with a different query string, the content doesn't seem to change. I believe this is because navigating between URLs that match the same <Route> doesn't change the content, but please correct me if I'm wrong. Given this, how do I use React Router for a set of URL's that need to differ only by query parameter? For example,

How to provide a history instance to a saga?

本小妞迷上赌 提交于 2019-12-06 02:51:01
问题 I would like to redirect to a new page after successful login. The routes (V4) are used like this: import { browserHistory } from '....browser_history_signleton'; ... class App extends Component { render() { const { authentication: { isSignedIn } } = this.props; return ( <ConnectedRouter history={browserHistory}> <div> <Header/> <Route exact path="/" component={Home}/> <PrivateRoute isAuthorized={isSignedIn} path="/page1" component={PageOne}/> <PrivateRoute isAuthorized={isSignedIn} path="

React Router URL parameters not working

丶灬走出姿态 提交于 2019-12-06 01:44:17
I'm unable to get the URL parameter feature in React Router to work, any insight would be helpful! I tried using the 'react-router-dom' instead of 'react-router' but I get the errors this guy is getting: https://github.com/ReactTraining/react-router/issues/1799 When I do localhost:8000, the app works. When I go to localhost:8000/123, the browser renders the index.html as is with no react. Is Express interfering with React? In Express all i have is the following: app.get('*', function response(req, res) { res.write(middleware.fileSystem.readFileSync(path.join(__dirname, 'dist/index.html')));