加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-router – 如何在特定路径上代理后端服务器?

发布时间:2020-12-15 20:49:31 所属栏目:百科 来源:网络整理
导读:这是路由配置: Route path='/' component={CoreLayout} IndexRoute component={HomeView}/ Route path='/404' component={NotFoundView}/ Redirect from='*' to='/404'//Route 这是webpack-dev-server的代理配置: proxy: { '/service': 'http://localhost:
这是路由配置:
<Route path='/' component={CoreLayout}>
  <IndexRoute component={HomeView}/>
  <Route path='/404' component={NotFoundView}/>
  <Redirect from='*' to='/404'/>
</Route>

这是webpack-dev-server的代理配置:

proxy: {
  '/service': 'http://localhost:8080'
}

快速服务器侦听3000端口.

我希望发送到http://localhost:3000/service的所有请求都将转移到http://localhost:8080,但似乎react-router处理所有请求并且代理不起作用.

任何人都知道如何解决这个问题?先感谢您

>检查 Webpack Dev Server文档,您需要提供具有目标属性的对象.
> htt-proxy-middleware文档显示了匹配模式的用法.

总之,我会尝试这样做:

proxy: {
  '/service/**': { target: 'http://localhost:8080' }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读