【已解决】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。。。

相关文章
|
6月前
Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed with multiple
Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed with multiple
37 1
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‘
428 0
|
3月前
|
JavaScript
成功解决:Failed to resolve directive: mode
这篇文章介绍了如何解决Vue中遇到的"Failed to resolve directive: mode"错误的两个常见原因及其解决办法:确保指令的单词拼写正确,以及在创建Vue实例之前注册全局指令。
成功解决:Failed to resolve directive: mode
|
5月前
|
存储 缓存 自然语言处理
“error“: { “root_cause“: [{ “type“: “circuit_breaking_exception“, “reason“: “[parent] D【已解决】
“error“: { “root_cause“: [{ “type“: “circuit_breaking_exception“, “reason“: “[parent] D【已解决】
46 1
error ‘res‘ is assigned a value but never used no
error ‘res‘ is assigned a value but never used no
|
6月前
|
数据安全/隐私保护 iOS开发 Perl
Encountered an unknown error (Could not find a `ios` simulator (valid values: )
Encountered an unknown error (Could not find a `ios` simulator (valid values: )
42 0
|
Linux
ERROR: 2 matches found based on name: network product-server_default is ambiguous
ERROR: 2 matches found based on name: network product-server_default is ambiguous
161 0
|
Unix Linux 异构计算
成功解决 ERROR: An error occurred while performing the step: “Building kernel modules“. See /var/log/nv
成功解决 ERROR: An error occurred while performing the step: “Building kernel modules“. See /var/log/nv
成功解决 ERROR: An error occurred while performing the step: “Building kernel modules“. See  /var/log/nv
|
Java Go API
译|Don’t just check errors, handle them gracefully(二)
译|Don’t just check errors, handle them gracefully(二)
96 0
|
程序员 Go API
译|Don’t just check errors, handle them gracefully(一)
译|Don’t just check errors, handle them gracefully
81 0