@@ -74,6 +74,10 @@ import Language.Javascript.JSaddle --TODO: Get rid of this - other platforms can
7474import Reflex.Dom.Core
7575import qualified GHCJS.DOM.Types as DOM
7676import Network.URI
77+#if defined(ios_HOST_OS)
78+import Data.Maybe (fromMaybe)
79+import qualified Data.List as L
80+#endif
7781
7882import Unsafe.Coerce
7983
@@ -201,7 +205,7 @@ class Reflex t => SetRoute t r m | m -> t r where
201205instance (Reflex t, Monad m) => SetRoute t r (SetRouteT t r m) where
202206 modifyRoute = SetRouteT . tellEvent . fmap Endo
203207
204−instance (Monad m, SetRoute t r m) => SetRoute t r (RoutedT t r m) where
208+instance (Monad m, SetRoute t r m) => SetRoute t r (RoutedT t r' m) where
205209 modifyRoute = lift . modifyRoute
206210
207211instance Prerender js m => Prerender js (SetRouteT t r m) where
@@ -266,12 +270,12 @@ runRouteViewT routeEncoder a = do
266270 -- is nonempty, but begins with a character that isn't '?'. Since we don't expect
267271 -- this ever to happen, we'll just handle it by failing completely with 'error'.
268272 route :: Dynamic t r
269− route = fmap (errorLeft . tryDecode theEncoder . (uriPath &&& uriQuery) . _historyItem_uri) historyState
273+ route = fmap (errorLeft . tryDecode theEncoder . (adaptedUriPath &&& uriQuery) . _historyItem_uri) historyState
270274 where
271275 errorLeft (Left e) = error (T.unpack e)
272276 errorLeft (Right x) = x
273277 (result, changeState) <- runSetRouteT $ runRoutedT a route
274− let f oldRoute change =
278+ let f (currentHistoryState, oldRoute) change =
275279 let newRoute = appEndo change oldRoute
276280 (newPath, newQuery) = encode theEncoder newRoute
277281 in HistoryStateUpdate
@@ -287,10 +291,32 @@ runRouteViewT routeEncoder a = do
287291 -- we can change this function later to accommodate.
288292 -- See: https://github.com/whatwg/html/issues/2174
289293 , _historyStateUpdate_title = ""
290− , _historyStateUpdate_uri = Just $ nullURI
291− { uriPath = newPath
292− , uriQuery = newQuery
294+ , _historyStateUpdate_uri = Just $ setAdaptedUriPath newPath $ (_historyItem_uri currentHistoryState)
295+ { uriQuery = newQuery
293296 }
294297 }
295− setState = attachWith f (current route) changeState
298+ setState = attachWith f ((,) <$> current historyState <*> current route) changeState
296299 return result
300+
301+-- On ios due to sandboxing when loading the page from a file adapt the
302+-- path to be based on the hash.
303+
304+adaptedUriPath :: URI -> String
305+#if defined(ios_HOST_OS)
306+adaptedUriPath = hashToPath . uriFragment
307+
308+hashToPath :: String -> String
309+hashToPath = ('/' :) . fromMaybe "" . L.stripPrefix "#"
310+#else
311+adaptedUriPath = uriPath
312+#endif
313+
314+setAdaptedUriPath :: String -> URI -> URI
315+#if defined(ios_HOST_OS)
316+setAdaptedUriPath s u = u { uriFragment = pathToHash s }
317+
318+pathToHash :: String -> String
319+pathToHash = ('#' :) . fromMaybe "" . L.stripPrefix "/"
320+#else
321+setAdaptedUriPath s u = u { uriPath = s }
322+#endif