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

项目内部路由跳转按需加载的文件无法传递cookie #341

Closed
PhoenixAve opened this issue Mar 26, 2020 · 3 comments · Fixed by #347
Closed

项目内部路由跳转按需加载的文件无法传递cookie #341

PhoenixAve opened this issue Mar 26, 2020 · 3 comments · Fixed by #347
Assignees
Labels
bug Something isn't working

Comments

@PhoenixAve
Copy link

PhoenixAve commented Mar 26, 2020

问题描述

注册项目时自定义了fetch方法,设置credentials为'include',但是项目内部路由跳转页面后获取按需加载的文件时没有携带cookie

相关环境信息

qiankun 版本 1.4.5

@kuitos
Copy link
Member

kuitos commented Mar 26, 2020

提供可复现的仓库

@PhoenixAve
Copy link
Author

PhoenixAve commented Mar 26, 2020

仓库地址:

https://github.com/PhoenixAve/qiankun-cookie
fetch携带cookie后,因为跨域资源访问不了了,可能麻烦作者自己解决一下了,之后当路由跳转获取js文件时,没有携带cookie

修改内容(/main/index.js)

主要就是在注册项目时传递了fetch,其他的跟仓库/example下代码一样
// 设置cookie

document.cookie = 'name=jack;password=123'
registerMicroApps([...], {}, {
  fetch: (url) => {
      return fetch(url, {
        credentials: 'include',
        mode: 'cors'
      })
   }
})

@PhoenixAve
Copy link
Author

在"dynamicHeadAppend.ts"文件的97行中找到"execScripts"函数的调用,此时传递了三个参数,并没有传递自定义的fetch函数,所以在"execScripts"函数内部会采用"defaultFetch",最终没有传递cookie到服务器,并且获取js文件时,content-type的值不正确,截图如下:

image

qiankun/src/hijackers/dynamicHeadAppend.ts文件第97行代码如下

...
execScripts(null, [src], proxy).then(
...
)

import-html-entry/src/index.js中第98行execScripts的定义部分如下

export function execScripts(entry, scripts, proxy = window, opts = {}) {
    const { fetch = defaultFetch } = opts;
    ...
}

@kuitos kuitos added the bug Something isn't working label Mar 26, 2020
@eynol eynol linked a pull request Mar 27, 2020 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants