【已解决】Error: Invariant failed: You should not use <withRouter(RouterView) /> outside a <Router>

简介: Error: Invariant failed: You should not use <withRouter(RouterView) /> outside a <Router>

Error: Invariant failed: You should not use <withRouter(RouterView) /> outside a <Router>

问题代码:

import React, {Component} from 'react';
import {BrowserRouter as Router, Route, Switch, withRouter} from 'react-router-dom';
import * as A from '../a';
import * as B from '../b';

class RouterView extends Component{
    render() {
        return (
            <Router>
                <Switch>
                    <Route path="/" component={A}/>
                    <Route path="/b" component={B}/>
                </Switch>
            </Router>
        );
    }
}

export default withRouter(RouterView)

解决:将BrowserRouter摘出来即可


over。。。

相关文章
Failed to execute script ‘xxx‘ due to unhandled exception:No module named ‘ctypes‘
Failed to execute script ‘xxx‘ due to unhandled exception:No module named ‘ctypes‘
460 0
|
4月前
|
Web App开发 监控 UED
如何解决Angular中的Error: HTTP request failed, call timeout问题
在Angular应用中,遇到HTTP请求超时错误`Error: HTTP request failed, call timeout`时,可通过多种途径解决。首先,可增加请求超时时间,Angular默认无超时限制,设置合理的超时时间如5秒有助于避免长时间等待无响应。其次,检查服务器响应时间,利用开发者工具监控网络请求,优化服务器端代码或调整超时值。最后,确认网络连接稳定性,使用`navigator.onLine`检测网络状态,并在不同网络环境中测试。这些策略共同作用,能够有效提升应用的稳定性和用户体验。
229 1
|
5月前
|
前端开发
Error in created hook: “TypeError: _test.default is not a function
Error in created hook: “TypeError: _test.default is not a function
error ‘res‘ is assigned a value but never used no
error ‘res‘ is assigned a value but never used no
|
6月前
|
关系型数据库 MySQL Linux
FATAL ERROR: Could not find my_print_defaults
FATAL ERROR: Could not find my_print_defaults
186 0
|
程序员 Go API
译|Don’t just check errors, handle them gracefully(一)
译|Don’t just check errors, handle them gracefully
83 0
|
Java Go API
译|Don’t just check errors, handle them gracefully(二)
译|Don’t just check errors, handle them gracefully(二)
100 0
|
关系型数据库 MySQL C++
Error:error C2601: ‘b‘ : local function definitions are illegal error C2063: ‘b‘ : not a function
Error:error C2601: ‘b‘ : local function definitions are illegal error C2063: ‘b‘ : not a function
191 0
|
JavaScript
Module not found: Error: Can‘t resolve ‘path‘
Module not found: Error: Can‘t resolve ‘path‘
999 0