Open ungoldman opened 7 years ago
from @bcomnes in https://github.com/hypermodules/hyperamp/issues/68:
This was another sheet-router bug I was running into. Basically, refreshing the app should work everywhere, but after you navigate around, you lose the base url so subsequent refreshes fail. The gif shows 1 working refresh (initial state) and one failed refresh at the end. I need to open an issue upstream. Going to 🛏 goodnight 🌖
Dumb fix is just adding .replace('file://', '')
. Regexes tho 💀
I tried that, but with the old regex. So close! 😭
I think this may be just be a hard limitation of running choo in electron without a server. sheet-router is just not set up to deal with the file protocol. Absolute links will always break on reload because /
will never map to /Users/.../cwd/index.html
.
When you reload with electron, it tries to reload whatever the current document.location
is. After navigating somewhere like /foo
then back to /
, choo/sheet-router's push state manipulation rewrites the location object to look something like:
ancestorOrigins: DOMStringList
assign: function ()
hash: ""
host: ""
hostname: ""
href: "file:///"
origin: "file://"
pathname: "/"
port: ""
protocol: "file:"
reload: function reload ()
replace: function ()
search: ""
So a reload will cause electron to try to load a file from file:///
. Since there is no file to load there, and choo isn't there to reinterpret the path to something relative to the initial index.html
, it will always fail.
I think for choo to work reliably in an electron environment, there either has to be a server, or sheet-router has to be rewritten to work specifically for an electron environment where routes don't correspond to server routes, and location.href needs to always point to the originating index.html.
Maybe only using hash routing in electron contexts is an interim solution?
We could also fix https://github.com/hypermodules/choo-location-electron to work with the new sheet router / choo. Things works pretty well using that arrangement.
Note: couldn't get hash routing to work in electron either
Switched to using nanorouter and hashes. Works great. Good to close.
Yay!
On Fri, Apr 21, 2017, 01:43 Bret Comnes notifications@github.com wrote:
Switched to using nanorouter and hashes. Works great.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/yoshuawuyts/sheet-router/issues/72#issuecomment-295971227, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWleoVBquR89J2dlU0NHOj6GjDXt9i3ks5rx-2ZgaJpZM4LPjfw .
One last fix needed for electron:
Electron pathname regex needs to be updated to account for
file:///
being equivalent to/
.steps to reproduce
/users
) and then back to root (/
)./
.Will try to send a PR today.