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

[Bug]: Url without .html extension returns with the content of index.html #7845

Open
1 of 3 tasks
richard-jfc opened this issue Jan 24, 2025 · 3 comments
Open
1 of 3 tasks
Labels

Comments

@richard-jfc
Copy link

richard-jfc commented Jan 24, 2025

Capacitor Version

💊 Capacitor Doctor 💊

Latest Dependencies:

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

Installed Dependencies:

@capacitor/android: not installed
@capacitor/cli: 7.0.1
@capacitor/core: 7.0.1
@capacitor/ios: 7.0.1

Other API Details

npm --version: 10.9.2
node --version: v22.13.1

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

When attempt to navigate to a url that matches a file but does not include the file's extension then the content of the index.html is returned.

  1. Web app opens index.html with a window.location: capacitor://localhost
  2. Follow a link with url ./another-page (Notice the missing .html extension)
  3. App loads capacitor://localhost/another-page but the response body is the content of index.html
Image

Expected Behavior

When the app loads capacitor://localhost/another-page the response body should be the content of another-page.html

Project Reproduction

https://github.com/richard-jfc/capacitor-url-bug

Additional Information

No response

@richard-jfc
Copy link
Author

It also doesn't work with subdirs:

A link ./subdir/ doesn't load subdir/index.html instead it returns the root index.html

I've updated the reproduction repo

@richard-jfc
Copy link
Author

richard-jfc commented Jan 27, 2025

It looks like the router assumes that any url with the extension missing is an SPA and should load the root index.html:

return basePath + "/index.html"

This doesn't work for multipage app routing like nextjs. Even turning on nextjs's trailingSlash option won't fix it because it always returns the root index.html, not the index.html of the path.

The solution would seem to be a series of attempts to find the file, and if it's missing fallback to the SPA handling.

The order should probably be:
Iff the path is missing an html extension:

  1. Is there a file that exists at the path? Return it
  2. Is there a file that exists at that path with a .html extension? return it
  3. Is there a file that exists at that path when /index.html is appended? return it
  4. Fall back to the root /index.html (to handle SPAs)

@richard-jfc
Copy link
Author

Looks like the only reason this is a problem is that [email protected] is doing MPA navigations rather than SPA navigations. It's probably a next bug because 14.1 is doing SPA navigations correctly.

However this issue is probably still valid - i'd expect /folder/ links to open /folder/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant