来自依赖项的错误无法解决

时间:2019-05-16 10:03:35

标签: javascript reactjs react-router

我有一个非常奇怪的问题,偶尔会发生一次,但我不知道它会触发什么。这是我相关的软件包版本:

"react-router@^4.3.1"
"react-router-dom@^4.3.1"

它可能与我猜测的版本有关,因为有时不会出现此问题。但是,当我删除node_modules并使用npm install构建项目时,出现以下错误:

browser.js:34 Uncaught Error: You should not use <Link> outside a <Router>
    at invariant (browser.js:34)
    at Link.render (Link.js:113)
    at finishClassComponent (react-dom.development.js:15320)
    at updateClassComponent (react-dom.development.js:15275)
    at beginWork (react-dom.development.js:16265)
    at performUnitOfWork (react-dom.development.js:20285)
    at workLoop (react-dom.development.js:20326)
    at HTMLUnknownElement.callCallback (react-dom.development.js:147)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:196)
    at invokeGuardedCallback (react-dom.development.js:250)
    at replayUnitOfWork (react-dom.development.js:19509)
    at renderRoot (react-dom.development.js:20439)
    at performWorkOnRoot (react-dom.development.js:21363)
    at performWork (react-dom.development.js:21273)
    at performSyncWork (react-dom.development.js:21247)
    at requestWork (react-dom.development.js:21102)
    at scheduleWork (react-dom.development.js:20915)
    at Object.enqueueSetState (react-dom.development.js:11596)
    at LoadableComponent.push../node_modules/react/cjs/react.development.js.Component.setState (react.development.js:336)
    at update (index.js:240)
    at index.js:250

我无法在Link之外使用Router

因此,即使我检出了项目的其他版本/分支,现在我仍然再次遇到此问题,然后删除node_modulespackage-lock.json,然后删除到npm install:问题无法解决。该错误信息与上面相同。

所以我的问题是:还有什么原因导致该问题不在其他分支上出现,而是在删除node_modules时突然出现在所有其他分支上?

编辑:

<HashRouter>
        <Switch>
          <Route exact path="/login" name="Login Page" component={Login} />
          <Route exact path="/activateprofile" name="Benutzerkonto aktivieren" component={Activation} />
          <Route exact path="/register" name="Register Page" component={Register} />
          <Route exact path="/404" name="Page 404" component={Page404} />
          <Route exact path="/500" name="Page 500" component={Page500} />
          <PrivateRoute path='/' component={DefaultLayout} />
        </Switch>
</HashRouter>

0 个答案:

没有答案