You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo Router静态导出部署到子路径时,publicPath与basePath配置不生效的问题求助

Expo Router静态导出部署到子路径时,publicPath与basePath配置不生效的问题求助

我最近在用Expo搭配Expo Router开发应用,打算导出成静态网站部署到子路径https://example.com/subpath下,导出用的命令是:
npx expo export --platform web --clear

但导出后发现生成的HTML和JS bundle都是从根域名加载资源,完全没用到我指定的子路径,这就很头疼:

  • ❌ 实际会去加载这些路径(不对的):
    https://example.com/_expo/static/js/...
    https://example.com/assets/...
  • ✅ 我期望它应该从这些子路径加载(才对的):
    https://example.com/subpath/_expo/static/js/...
    https://example.com/subpath/assets/...

为了搞定这个问题,我已经试了好几种配置了,单独用、组合用都试过,但就是没效果:

  • app.json里加了:
    expo.web.publicPath = '/subpath/'
  • web.config.json里配置了:
    output.publicPath='/subpath/'
  • 还写了webpack.config.js:
    const createExpoWebpackConfigAsync = require('@expo/webpack-config');
    module.exports = async function (env, argv) {
      const config = await createExpoWebpackConfigAsync(env, argv);
      config.output.publicPath = '/subpath/';
      return config;
    };
    
  • 甚至专门加了个router.config.js:
    module.exports = {
      basePath: '/subpath/',
    };
    

我实在搞不懂哪里出问题了,官方文档翻了好几遍也没找到明确的解决指引,之前找的AI工具也没能帮我解决。有没有大佬能指点一下?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 12:29:29