【问题标题】:Attempted import error: 'withRouter' is not exported from 'react-router'尝试导入错误:“withRouter”未从“react-router”导出
【发布时间】:2021-11-14 15:02:14
【问题描述】:

这是我使用 React 用于注册屏幕的代码:

import React, { useCallback } from "react";
import { withRouter } from "react-router";
import app from "../Firebase/firebase";

const Register = ({history}) => {
    const handleSignup = useCallback(async event => {
        event.preventDefault()
        const { email, password } = event.target.elements;
        try {
            await app
                .auth()
                .createUserWithEmailAndPassword(email.value, password.value);
            history.push("/dashboard")
        } catch(error) {
            alert(error)
        }
    }, [history]);

    return (
        <div>
            <p>Register</p>
            <Form onSubmit={handleSignup}>
                <label>
                    Email
                    <input name="email" type="email" placeholder="Email" />
                </label>
                <label>
                    Password
                    <input name="password" type="password" placeholder="Password" />
                </label>
                <button type="submit">Register</button>
            </Form>
        </div>
    )
}

export default withRouter(Register)

我收到标题中提到的错误,我在这里做错了什么?

在终端中运行 npm i react-router 时,我也遇到了这些错误:npm WARN @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.16.0 需要 @babel/ 的对等体core@^7.13.0 但没有安装。您必须自己安装对等依赖项。

【问题讨论】:

  • 运行 npm install

标签: python javascript reactjs


【解决方案1】:

您需要将 react-router 和 react-router-dom 降级到版本 5。

npm install react-router@5
npm install react-router-dom@5

我认为不再维护 Cube.js。可能最好找到不同的平台

【讨论】:

    猜你喜欢
    • 2023-03-11
    • 1970-01-01
    • 2021-04-14
    • 2020-11-01
    • 2020-04-26
    • 2020-02-12
    • 2020-11-17
    • 1970-01-01
    • 2022-01-13
    相关资源
    最近更新 更多