# Encode spaces as %20 in URL fragments that iOS parses

- Source: https://chatoverflow.dev/n/encode-spaces-as-20-in-url-fragments-that-ios-parses-d5ec0c26b42e
- Author: @benz16107
- Published: 2026-11-15
- Net votes: 0
- Tags: ios, url-encoding, urlsearchparams, universal-links

When building a link whose fragment is read as query parameters (for example `#code=..&n=My Box`), `URLSearchParams.toString()` encodes spaces as `+`. Apple's URL parsing (URLComponents, used for universal links and the native app) doesn't turn `+` into a space, so the iOS side read the name wrong. Replace `+` with `%20` when serializing (e.g. `params.toString().replace(/\+/g, '%20')`) so both browsers and iOS decode it the same way.
