简体   繁体   English

React-Router (experimental v6) 渲染问题?

[英]React-Router (experimental v6) render problem?

I recently installed react-router and react-router-dom experimental versions for a simple SPA I am making.我最近为我正在制作的简单 SPA 安装了 react-router 和 react-router-dom 实验版本。 Post-install, the dev server compiled and started just fine:安装后,开发服务器编译并启动得很好:

Compiled successfully!

You can now view rcg in the browser.

However, in the browser on localhost, I get the following:但是,在本地主机上的浏览器中,我得到以下信息:

TypeError: Object(react__WEBPACK_IMPORTED_MODULE_3__["unstable_useTransition"]) is not a function. (In 'Object(react__WEBPACK_IMPORTED_MODULE_3__["unstable_useTransition"])({
timeoutMs: b })', 'Object(react__WEBPACK_IMPORTED_MODULE_3__["unstable_useTransition"])' is an instance of Object)

BrowserRouter
/Users/user/.tsc-output/react-router-dom/index.js:48
  45 | export function BrowserRouter({ children, timeoutMs = 5000, window }) {
  46 |     let historyRef = React.useRef();
  47 |     if (historyRef.current == null) {
> 48 |         historyRef.current = createBrowserHistory({ window });
  49 |     }
  50 |     // @ts-ignore
  51 |     let [startTransition, isPending] = React.unstable_useTransition({

./src/index.js
src/index.js:7
   4 | import App from './App';
   5 | import * as serviceWorker from './serviceWorker';
   6 | 
>  7 | ReactDOM.render(
   8 |   <React.StrictMode>
   9 |     <App />
  10 |   </React.StrictMode>,

There's a few other blocks, but I am wondering if the problem lies in the above two.还有其他几个块,但我想知道问题是否出在上述两个块上。 Anyone have insight into what the issue might be?任何人都知道问题可能是什么? Would it be caused by my somewhat spur-of-the-moment switch to experimental react-router and react-router-dom?会不会是由于我一时冲动切换到实验性 react-router 和 react-router-dom 造成的?

Also: package.json{另外:package.json{

"name": "rcg",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "bootstrap": "^4.5.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-router": "0.0.0-experimental-b1ff171f",
    "react-router-dom": "0.0.0-experimental-b1ff171f",
    "react-scripts": "3.4.1",
    "tsutils": "^3.17.1",
    "typescript": "^3.9.3"

App.js应用程序.js

import React from 'react';
import "bootstrap/dist/css/bootstrap.min.css"
import { BrowserRouter, Route} from "react-router-dom";

import Navbar from "./components/navbar.component"
import BackendRoutes from "./components/backend-routes.component"

function App() {
  return (
    <BrowserRouter>
        <Navbar />
        <Route path="/backend" element={BackendRoutes} />
    </BrowserRouter>
  );
}

export default App;

You miss history package你错过了history package

yarn add history

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM