Antd of React中使用<Redirect from = "/" to="/home"/>出现异常

#1

我是react新手,最近在学习antd of react。想实现一个当用户输入网址后,利用Redirect标签自动跳转到首页的功能。但是使用<Redirect exact from = "/" to="/home"/>出现异常,请各位大神帮帮忙,看看问题出现在哪里。源码如下:

//app.js当输入网址后显示整体布局Admin组件
export default class App extends Component {
  render () {
    return (
      <BrowserRouter>
        <Switch> {/*只匹配其中一个*/}
          <Route path='/login' component={Login}></Route>
          <Route path='/' component={Admin}></Route>
        </Switch>
      </BrowserRouter>
    )
  }
}
//Admin.jsx布局组件,组件渲染时在Content中渲染Home组件
const { Footer, Sider, Content } = Layout;
export default class Admin extends Component {
  render() {
    return (
      <Layout style={{ minHeight: "100%" }}>
        <Sider>
          <LeftNav />
        </Sider>
        <Layout>
          <Header>Header</Header>
          <Content style={{margin: 20, backgroundColor: '#fff'}}>
            <Switch>
              <Redirect exact from = "/" to="/home"/>
              <Route path="/home" component={Home} />
              <Route path="/category" component={Category} />
              {/* <Route path='/' component={Home}/>使用此种方式可正常渲染Home组件 */} 
            </Switch>
          </Content>
          <Footer>Footer</Footer>
        </Layout>
      </Layout>
    );
  }
}
//home.jsx Home组件
export default class Home extends Component {
  render() {
    return (
      <div>
        主页
      </div>
    )
  }
}

在整体布局Admin组件中我使用<Redirect exact from = "/" to="/home"/>使Home组件显示在Antd的Content中,但出现如下异常:

TypeError: path_to_regexp__WEBPACK_IMPORTED_MODULE_8___default.a.compile is not a function
at compilePath (react-router.js:235)
at generatePath (react-router.js:258)
at react-router.js:277
at updateContextConsumer (react-dom.development.js:19811)
at beginWork$1 (react-dom.development.js:20186)
at HTMLUnknownElement.callCallback (react-dom.development.js:337)
at Object.invokeGuardedCallbackDev (react-dom.development.js:386)
at invokeGuardedCallback (react-dom.development.js:439)
at beginWork$$1 (react-dom.development.js:25723)
at performUnitOfWork (react-dom.development.js:24649)
at workLoopSync (react-dom.development.js:24622)
at performSyncWorkOnRoot (react-dom.development.js:24211)
at scheduleUpdateOnFiber (react-dom.development.js:23638)
at updateContainer (react-dom.development.js:27047)
at react-dom.development.js:27464
at unbatchedUpdates (react-dom.development.js:24376)
at legacyRenderSubtreeIntoContainer (react-dom.development.js:27463)
at Object.render (react-dom.development.js:27548)
at Module…/src/index.js (index.js:8)
at webpack_require (bootstrap:785)
at fn (bootstrap:150)
at Object.0 (main.chunk.js:1581)
at webpack_require (bootstrap:785)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at main.chunk.js:1

#2

问题已解决,原来是使用vs code中左侧npm脚本面板中的start按钮启动服务导致。使用这个按钮好像无法使用某些系统环境变量,致使出现这么奇葩的错误。