[Bug]: Capacitor WebView treats URLs with dots as file requests, breaking SPA routing and page reload.

未关闭
#8,085 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

  • #8135 来自 @iamriajul —— 已关闭,未合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
android, ios, typescript
领域
mobile, web-dev

调研方向

首先,在 iOS 和 Android 上使用链接的 Capacitor 项目复现该问题,重点关注包含点的路由的 WebView 导航。将这些请求与资源请求进行比较,并验证非资源 URL 会提供 index.html,以确保 SPA 路由和页面重新加载在两个平台上都能正常工作。

由索引模型根据 Issue 内容生成。

描述

platform: android platform: ios type: bug
Capacitor Version

💊 Capacitor Doctor 💊

Installed Dependencies:

@capacitor/cli: 7.4.2
@capacitor/core: 7.4.2
@capacitor/android: 7.4.2
@capacitor/ios: 7.4.2

[success] iOS looking great! 👌
[success] Android looking great! 👌

Other API Details

Platforms Affected
  • iOS
  • Android
  • Web
Current Behavior

When navigating to URLs that contain dots (.) in the path, Capacitor's WebView treats them as file requests rather than SPA routes. This causes a 404 error instead of serving the index.html file for client-side routing.

For example:

  • http://localhost/@username → Works (serves index.html)
  • http://localhost/@user.name → Fails (404 - treats as file request)
  • http://localhost/page.section → Fails (404 - treats as file request)

And shows console error in Xcode:
⚡️ WebView failed provisional navigation
⚡️ Error: The file “@user.name” couldn’t be opened because there is no such file.

And in Android, An error page is shown with Page is not available.

Image
Expected Behavior

All non-asset URLs should serve index.html to allow the SPA router to handle routing, regardless of whether the URL contains dots.

Project Reproduction

https://github.com/iamriajul/capacitor-dot-in-urls-spa-navigation-issue-reproduction

Additional Information

No response

主要语言
TypeScript
星标
17.1k
派生
1.3k
平均合并
1 天 22 小时
30 天内合并 PR
26

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ionic-team/capacitor 的其他 Issue

查看 ionic-team/capacitor 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。