import React, {PropTypes} from 'react';
export default class Login extends React.Component {
constructor(props) {
super(props)
this.handleLogin = this.handleLogin.bind(this)
}
handleLogin(event) {
event.preventDefault()
// do some login logic here, and if succes
我已经阅读了这里关于如何做到这一点的文章,并选择了withRouter(({ history }) => history.push("/"));方法,但我的以下代码不起作用。我做错了什么? import React from "react";
import SearchBox from "./SearchBox";
import { withRouter } from "react-router-dom";
class SearchParams extends React.Component {
handleSear
我正在尝试将react路由器与TypeScript一起使用。但是,我在使用withRouter函数时遇到了一些问题。在最后一行,我得到了一个非常奇怪的错误:
Argument of type 'ComponentClass<{}>' is not assignable to parameter of type 'StatelessComponent<RouteComponentProps<any>> | ComponentClass<RouteComponentProps<any>>'.
Type
我有一个搜索组件调用我的API,我想将数据传递到结果页面。相反,我得到了这个错误:
TypeError:无法读取未定义的属性“location”
我试着在网上到处寻找解决方案,但它不能解决我的问题。我做错了什么?
app.js
import React from 'react';
import logo from './logo.svg';
import './App.css';
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom
我是新来的反应和javascript。我一直在学习路由器,我遵循的一个教程是使用withRouter。无论如何,我发现了一些代码如何重新实现withRouter,因为它不再受支持。我的问题如下。内部函数如何获得道具参数。它是从哪里来的?谢谢大家的回复,我已经坚持了一段时间了。
function withRouter(Component) {
function ComponentWithRouterProp(props) {
let location = useLocation();
let navigate = useNavigate();
let params =
我有以下内容:
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { logoutUser } from '../actions';
class NavBar extends Component {
onLogoutClick() {
this.props.logoutUser();
this.props.history.push('/login'); // here is the
我想呈现一个导航栏与链接登录和注册页面,但每当我点击他们的url更改,我希望他们,但各自的组件没有呈现。这是我的密码:
App.js
import React, { Component } from 'react';
import NavBar from './components/NavBar/NavBar';
import {BrowserRouter as Router,Route,withRouter} from "react-router-dom";
import Login from './components/Login
Failed to compile. Attempted import error: 'withRouter' is not exported from 'react-router-dom'. 我的代码喜欢,而且我已经安装了react-router-dom的react-route,现在我有10次重新输入应用程序 import React from 'react';
import {withRouter} from 'react-router-dom';
import './menu-item.scss';
c