Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack 配置代理后路由跳转有问题 #13

Closed
1 task done
lin-mt opened this issue Nov 19, 2021 · 7 comments
Closed
1 task done

webpack 配置代理后路由跳转有问题 #13

lin-mt opened this issue Nov 19, 2021 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@lin-mt
Copy link

lin-mt commented Nov 19, 2021

Basic Info

  • Package Name And Version: "@arco-design/webpack-plugin": "^1.5.2"
  • System: mac os
  • Browser: chrome
  • Reproduction Link: 官方是否可以提供一个简易的 jsfiddle/codepen/codesandbox 例子,我们再根据这个例子 fork 出来重现 bug,这样会方便一点~

What is expected?

登陆成功后,正常跳转

Steps to reproduce

如果有登陆,先退出登陆

  1. 在 webpack.config.js 添加配置
  config.devServer = {
    proxy: {
      '/simpleProxy': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        pathRewrite: { '^/simpleProxy': '' },
      },
    }
  }
  1. 输入账号密码,点击登陆

image

  1. 浏览器重新访问 http://localhost:9090/ 后,才可以正常访问
@kirazxyun
Copy link
Member

webpack 配置是没有问题的是跳转的路由不正确,这是个问题,我们改一下。

@kirazxyun kirazxyun added the bug Something isn't working label Nov 19, 2021
@kirazxyun kirazxyun self-assigned this Nov 19, 2021
@zmzimpl
Copy link

zmzimpl commented Dec 10, 2021

webpack 配置是没有问题的是跳转的路由不正确,这是个问题,我们改一下。

改好了吗?还是存在这个问题

@Queensbarry
Copy link
Contributor

Queensbarry commented Dec 10, 2021

以上问题实质上是由于 history 特性造成的,history 模式不像 hash 模式,用 # 来区分前后端路由,可以增加下述两行代码避免 history 下后端代理失效(实质上是 webpack-dev-server少了配置)

inline: true
historyApiFallback: true

webpack.config.js 该部分完整配置如下:

config.devServer = {
  inline: true,
  historyApiFallback: true,
  proxy: {
    '/api': {
      target: 'http://localhost:8080',
      changeOrigin: true,
      pathRewrite: {
         '^/api': '' 
      },
    },
  }
}

@melong007
Copy link

@Queensbarry 这个可以在Arco Pro 最佳实践 加个示例?
image

@kirazxyun
Copy link
Member

@Queensbarry 这个可以在Arco Pro 最佳实践 加个示例? image

可以的,近期的版本会加上。

@kirazxyun kirazxyun pinned this issue Dec 22, 2021
@lin-mt lin-mt closed this as completed Jan 10, 2022
@BongBongBang
Copy link

@Queensbarry 这个可以在Arco Pro 最佳实践 加个示例? image

大佬,您这张截图,不是官网的截图,是您自己本地的吧?

@Queensbarry
Copy link
Contributor

@Queensbarry 这个可以在Arco Pro 最佳实践 加个示例? image

大佬,您这张截图,不是官网的截图,是您自己本地的吧?

这个是 1.* 版本的时候写的了,现在应该是写在 config-overrides.js 中了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants