Webpack-dev-server设置的proxy被react-router拦截了

#1

如题,在本地起了个端口3000的react服务器,和一个端口8090json-server 。我想把localhost:3000/api/这样的请求都导向到json-server上面,在webpack-dev-server中设置了proxy

  proxy: {
    '/api': {
      target: 'http://localhost:8090',
      secure: false
    }
  }

但每次访问的时候react-router总是提示Warning: [react-router] Location "/api" did not match any routes
并没有将api的请求导向到http://localhost:8090上去

proxy配置有问题还是react-router没处理好呢?有人遇到这个问题吗?

#2

ok了~ 是proxy的规则没生效,这里我是配置在了webpack.config.dev.js里面了。重新在webpackDevServer的配置里面配置一个proxy就好了

#3

在config中定义:
proxyTable: {
‘/api’:{
target:‘https://sspai.com’,
host:‘sspai.com’,
changeOrigin:true
},
‘/v1’: {
target: ‘https://sspai.com/api’,
host: ‘sspai.com/api’,
changeOrigin:true,
}

}