react-router-dom

Updating Store Before Custom Route

谁都会走 提交于 2020-01-06 05:30:08
问题 I am designing react application with node server. I have created a custom Private Route import React from 'react'; import {connect} from 'react-redux'; import {Route, Redirect} from 'react-router-dom'; class PrivateRoute extends React.Component{ render() { const { isAuthenticated, component: Component, ...rest } = this.props; return ( <Route {...rest} component={(props) => { if(isAuthenticated){ return <Component {...props}/> } else{ return <Redirect to="/login" /> } }}/> ) } } const

react-router-dom Build Giving 404 When Accessing URL Directly, But Not In Development

喜欢而已 提交于 2020-01-06 05:27:08
问题 I have a react app created with create-react-app and am using react-router-dom for routing. The general layout is: App.js <BrowserRouter> <BodyContent /> </BrowserRouter> Bodycontent.js <Fragment> <Navigation/> <main> <ScrollToTopRoute path="/" exact component={HomePage}/> <ScrollToTopRoute path="/page1" exact component={Page1}/> <ScrollToTopRoute path="/page1/page2" exact component={Page2}/> <ScrollToTopRoute path="/page3" exact component={Page3}/> ... etc... </main> </Fragment> The

React Router (Dom) v4 redirect to different route upon input enter key press

喜欢而已 提交于 2020-01-03 03:16:09
问题 I am trying to redirect to new route when user presses enter on input field. I have a Title and Search component that I want rendered on every page. I have found different use cases with using Redirect component, withRouter component, using context, and possibly passing history object to my Search component which is where the input field lives. Any help would be appreciated.. App.js (main component) import React, { Component } from 'react'; import { BrowserRouter as Router, Route, Switch }

React Router Error related to Link To

隐身守侯 提交于 2020-01-01 14:56:35
问题 I am trying to route the components from one to another, i am getting errors related to the react router link and the error for the react router is - Failed to compile i have tried using react router and added its package to my project library. here are code for the what i made for doing the route:- 1) [Index.js file][2] 2) [Navlink.js file][3] 3) [nav.js file][4] In Index.js i have made a router in render method but it shows errors above. In Navlink.js i have made a link return class which

Bugs in Sidebar Menu with React Router V4

老子叫甜甜 提交于 2020-01-01 08:36:15
问题 I'm developing a single-page ReactJS Web app but I know I'm doing something wrong while defining my routing with React Router V4 . My problem is as follows: PrivateRoute in my routes.js file is not working as expected. That is, I don't know why but my sidebar menu, which is a child component of my main App , does not work properly: there are a few bugs when I click on the menu item of my PrivateRoute component (in this case, Page1 ). When I say bugs, I mean that when I click on the menu item

Redirect to third party url using react-router-dom

拟墨画扇 提交于 2019-12-30 13:38:05
问题 I'm very much aware of the react-router-dom I want to do a conditional rendering of the component. If use is not logged in redirect him to some third party URL for example, the below code looks neat and works fine <Route exact path="/home" render={() => ( isLoggedIn() ? ( <Redirect to="/front"/> ) : ( <Home /> ) )}/> Let's say in the above example if I want to redirect to https://www.google.com how can I do it? if I write <Redirect to="https://www.google.com"> it gives me error. How can I

react 的环境搭建(新)(2018/12/15)

一笑奈何 提交于 2019-12-28 00:17:33
一、react环境的搭建 1 全局安装(react 脚手架的安装):cnpm install create-react-app -g 2 局部安装(在文件路径下):create-react-app 项目名称 //相当于创建了一个myrouter的文件夹 3 cd myrouter 进去myrouter 文件夹 4 npm start 会自动开启项目的网页 package.json "scripts": { "start": "react-scripts start", //启动项目 "build": "react-scripts build", //打包项目 "test": "react-scripts test", //测试项目 "eject": "react-scripts eject" //暴露webpack的配置文件,一但暴露出去就不能更改 }, 单页面开发 是根据用户请求页面数据的不同去重新渲染页面 二、react路由的安装和使用 (1)在myrouter文件路径下进去cmd------>yarn add react-router-dom --dev(安装路由插件) (2)在需要使用路由的组件内部引入路由--------> import {HashRouter as Router,Route,Link,NavLink} from "react-router-dom"

React路由

♀尐吖头ヾ 提交于 2019-12-25 16:39:40
React路由 1.React路由的安装 在项目命令行中,执行 cnpm install react-router-dom -S 下载到生产环境的依赖中。 在组件中通过对象的解构方式去获取到react-router-dom内置组件,在组件中,按需引入内置组件,在页面中进行使用: 2.React路由内置组件 HashRouter表示一个路由的根容器,将来所有的路由相关的东西,都要包裹在HashRouter里面,而且一个网站中,只需要使用一次HashRouter就好了; Route表示一个路由规则,在Route上,有两个比较重要的属性,path,component Link表示一个路由的链接 2.1HashRouter和BrowserRouter的区别; BrowserRouter:   原理是H5的history API,IE9及以下不兼容,需要由web server支持,在web client这边window.location.pathname被react router解析,example.com/react/route    HashRouter:   原理是URL的hash,不需要由web server支持,因为它的只有‘/’path需要由web server支持,而#/react/route URL不能被web server读取,在web client这边window

React. Basic example of re-rendering using react-router. +100 rep

删除回忆录丶 提交于 2019-12-24 19:45:13
问题 I'm newbie. And I'm newbie at React . I'm trying react-router . I saw this example: https://reacttraining.com/react-router/web/example/basic. I reproduced it on Codesandbox.io here: https://codesandbox.io/s/7jxq0j6qp0 I don't understand why the Menu is re-rendering itself when I change URL using menu's links. If you open console you can see it. Why? I think it should not re-render itself. Just the route section. Where am I wrong? 回答1: You can write your component as PureComponent. Since there

Prevent URL encoding that is removing equals signs from URL

无人久伴 提交于 2019-12-24 19:41:47
问题 Working on a Django/React app. I have some verification emails links that look like the following: https://test.example.com/auth/security_questions/f=ru&i=101083&k=7014c315f3056243534741610545c8067d64d747a981de22fe75b78a03d16c92 In dev env this works fine, but now that I am getting it ready for production, it isn't working. When I click on it, it converts it to: https://test.example.com/auth/security_questions/f%3Dru&i%3D101083&k