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

相关文章
|
缓存 PHP
Composer 报错 Error while processing content unencoding: Unknown failure within ...
Composer 报错 Error while processing content unencoding: Unknown failure within ...
212 0
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‘
438 0
|
4月前
|
JavaScript
成功解决:Failed to resolve directive: mode
这篇文章介绍了如何解决Vue中遇到的"Failed to resolve directive: mode"错误的两个常见原因及其解决办法:确保指令的单词拼写正确,以及在创建Vue实例之前注册全局指令。
成功解决:Failed to resolve directive: mode
|
6月前
|
存储 缓存 自然语言处理
“error“: { “root_cause“: [{ “type“: “circuit_breaking_exception“, “reason“: “[parent] D【已解决】
“error“: { “root_cause“: [{ “type“: “circuit_breaking_exception“, “reason“: “[parent] D【已解决】
49 1
error ‘res‘ is assigned a value but never used no
error ‘res‘ is assigned a value but never used no
|
7月前
|
自然语言处理 数据库
Expected one result (or null) to be returned by selectOne(), but found: 2
Expected one result (or null) to be returned by selectOne(), but found: 2
97 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
|
程序员 Go API
译|Don’t just check errors, handle them gracefully(一)
译|Don’t just check errors, handle them gracefully
82 0
|
Java Go API
译|Don’t just check errors, handle them gracefully(二)
译|Don’t just check errors, handle them gracefully(二)
97 0