1

I have a react app with the following routes:

example.com/ example.com/policy

When I try to access example.com/ from my iOS app's WKWebView It is rendering the proper homepage. but when I try to access example.com/policy nginx returns a 404 error in WKWebView. All pages seems to work normally in all Mobile/Desktop Browsers.

access.log when accessing example.com/policy in normal browsers:

[18/Aug/2018:17:10:06 +0000] "GET /js/main.js HTTP/1.1" 304 0 "https://www.example.com/policy" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like $

[18/Aug/2018:17:10:06 +0000] "GET /js/jquery-1.11.3.min.js HTTP/1.1" 304 0 "https://www.example.com/policy" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 $

[18/Aug/2018:17:10:06 +0000] "GET /js/plugins.js HTTP/1.1" 304 0 "https://www.example.com/policy" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, li$

[18/Aug/2018:17:10:07 +0000] "GET /service-worker.js HTTP/1.1" 200 3164 "https://www.example.com/service-worker.js" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit$

accessing the same route in iOS app's WKWebView below is the access.log: [18/Aug/2018:17:13:45 +0000] "GET /policy HTTP/1.1" 404 152 "-" "Mozilla/5.0 (iPad; CPU OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko)"

I'd like to know if this is some Issue with the React Router which prevents it from rendering the content although I'm very sure that the problem is not with the content.

UPDATE: The Issue was with Nginx translating the URL routes to my React app. I'm using React-router-dom to manage the React App's routes. I added the following lines to the nginx conf file and it worked fine.

location /policy {
rewrite ^/policy(.*) /$1 break;
proxy_pass http://example.com/policy;
}
Om Prakash
  • 29
  • 2
  • 5

1 Answers1

1

How are you managing routing in your app? History prop or href? If you’re using href then you need to override loadUrl method in iOS. It would be great if you share codesandbox or code snippet here.

Sakhi Mansoor
  • 6,103
  • 4
  • 17
  • 31
  • The problem was with Nginx conf translating the react routes. I added the following lines to nginx conf and it worked fine. `location /policy { rewrite ^/policy(.*) /$1 break; proxy_pass http://example.com/policy; }` – Om Prakash Aug 19 '18 at 06:12