react-router-dom

How to navigate on path by button click in react router v4?

跟風遠走 提交于 2020-01-30 18:22:56
问题 I have this paths in react-router-dom: <BrowserRouter> <div> <Route exact path='/(index.html)?' component={Home}/> {/* app = home */} <Route path='/register' component={Registration}/> </div> </BrowserRouter> everything is working fine, now anywhere in my components I want to change path by onClick, a code like this: <button onClick={() => history.push('/the/path') }> change path </button> how can I do that? 回答1: import {withRouter} from 'react-router-dom'; ... class App extends React

How to navigate on path by button click in react router v4?

旧城冷巷雨未停 提交于 2020-01-30 18:20:08
问题 I have this paths in react-router-dom: <BrowserRouter> <div> <Route exact path='/(index.html)?' component={Home}/> {/* app = home */} <Route path='/register' component={Registration}/> </div> </BrowserRouter> everything is working fine, now anywhere in my components I want to change path by onClick, a code like this: <button onClick={() => history.push('/the/path') }> change path </button> how can I do that? 回答1: import {withRouter} from 'react-router-dom'; ... class App extends React

Trying to go back to “/” in react router?

梦想与她 提交于 2020-01-30 05:40:05
问题 So what I want is to have a top-level routing in App.js that routes to Home on "/". In Home i want to render a few things and then one place where I chose what to render based on the path. i.e. if the path is "/" I want to show a Link that can take me to "/about", if the path is "/about" I'll show the About component there. In App.js I always have a Link that can take me back to "/". So App.js render this: <Router> <div> <Link to="/"> <button>Go to home</button> </Link> <Route exact path="/"

react-router-dom5.x使用示例

南笙酒味 提交于 2020-01-27 05:19:19
react-router-dom5.x使用示例 安装 使用 BasicExample--基础实例 UrlParams--动态路由 Nesting--嵌套路由 AuthRoute--路由鉴权 CustomLink--自定义路由 PreventingTransitions--阻止过渡 NO Match--404 Sidebar 侧边栏 config 路由配置 Query parameters 查询参数 学习资源推荐 微信扫码关注公众号 : 前端前端大前端 ,追求 更精致 的阅读体验 ,一起来学习啊 关注后发送关键 资料 ,免费获取一整套前端系统学习资料和老男孩python系列课程 安装 npm install --save react-router-dom 使用 import React from 'react' ; import { BrowserRouter as Router , Route , Link } from "react-router-dom" ; import Home from './components/Home' import News from './components/News' import Music from './components/Music' //exact表示严格匹配,去掉的话,访问/news实际会渲染Home,News两个组件

react-router-dom: getting props.location from within <BrowserRouter> component

心不动则不痛 提交于 2020-01-23 07:00:15
问题 I have a simple App that uses BrowserRouter from 'react-router-dom' v4. I'm trying to access the location.pathname property from within the <BrowserRouter/> component, without avail: class App extends Component{ render(){ return ( <BrowserRouter> // How do I access this.props.location? <div className={(this.props.location.pathnme === "/account") ? "bgnd-black" : "bgnd-white"} > <Switch> <Route path="/login" component={LoginPage}/> <Route path="/success" component={LoginSuccess}/> <Route path=

react-router-dom: getting props.location from within <BrowserRouter> component

六眼飞鱼酱① 提交于 2020-01-23 06:59:07
问题 I have a simple App that uses BrowserRouter from 'react-router-dom' v4. I'm trying to access the location.pathname property from within the <BrowserRouter/> component, without avail: class App extends Component{ render(){ return ( <BrowserRouter> // How do I access this.props.location? <div className={(this.props.location.pathnme === "/account") ? "bgnd-black" : "bgnd-white"} > <Switch> <Route path="/login" component={LoginPage}/> <Route path="/success" component={LoginSuccess}/> <Route path=

React Router Dom redirect from redux action creator

余生长醉 提交于 2020-01-16 14:07:56
问题 I am working in a Web application (built using React+Redux+React Router Dom) and Firebase as backend. My question is: Is possibile to carry out a Redirect from an action creator (so, outside the react router dom components ) ? For example: I want user to be redirected to Home after an operation of deletion of an item: export const deleteItem = (item) =>{ const id = firebase.auth().currentUser.uid; var itemRef = firebase.database().ref("users/"+id+"/items/"+item); return dispatch =>{ dispatch(

react的插件

拜拜、爱过 提交于 2020-01-10 10:59:39
1、cnpm add antd --安装antd插件 2、yarn add react-router --安装route路由 react-router-dom依赖react-router,所以我们使用npm安装依赖的时候,只需要安装相应环境下的库即可,不用再显式安装react-router。基于浏览器环境的开发,只需要安装react-router-dom;基于react-native环境的开发,只需要安装react-router-native。npm会自动解析react-router-dom包中package.json的依赖并安装。 3、 yarn add react-router-dom axios less-loader --安装必要插件 来源: CSDN 作者: weixin_43233988 链接: https://blog.csdn.net/weixin_43233988/article/details/103897153

passing redux store in props coming as undefined?

做~自己de王妃 提交于 2020-01-10 05:56:25
问题 When I am passing the store from let store = createStore(myReducer); in props to other component it is coming undefined. this is happening whenI am using react-router-dom but without that it is coming alright. The route part the route is in App component <BrowserRouter> <div> <Route path={"/layout"} component={Home} /> <Route path={"/form"} component={UserForm} /> <Route exact path={"/"} component={this.layout} /> </div> </BrowserRouter layout method layout(){ return ( <Layout store={this

Simple Conditional Routing in Reactjs

风流意气都作罢 提交于 2020-01-09 04:25:09
问题 How to make conditional Routing, if and only if some conditions satisfies then only routing should happen. for example, if and only if the user enters the correct credentials login should be successful and the user should be able to see the welcome page. if we hit directly some URL like 'localhost:8080/welcome' that should not be navigated to welcome page, only after login welcome page should be seen. how can I achieve this, can anyone help me please..thank you. App.js import React, {