Open paulproteus opened 9 years ago
@paulproteus I tried adding that script to the head of my page, however it doesn't look like it's helping. I visit one of my fullscreen notes, refresh, and I'm back at the brainstorm homepage.
Hmm, interesting. For what it's worth, I did write that with page-reload-based web apps in mind.
For Meteor, presumably the thing to do is to add it to some part of Iron Router. I'm not sure at the moment what the answer would be. @kentonv or @jparyani likely have more experience with that.
Thinking out loud: maybe what you need here is a function that reactively looks at window.location
(or a Meteor reactive version of window.location
) and then runs the code on my gist.
https://github.com/tmeasday/meteor-router/wiki/Split-API provides something like that, but note it's not for Iron Router.
It looks like maybe IronRouter.path
is a reactive variable that does what we want.
IronRouter.path seems to change reactively to what we want, except that it lags behind one route!
If I'm on home, and then click manage boards. The url is then "bla.sandstorm.io/bla/home", even though it should be ".../manageBoards" instead!
Tracker.autorun(function () {
var path = Router.current();
if (path) {
window.parent.postMessage({'setPath': location.pathname + location.hash}, '*');
}
});
Same goes for the Router.after(function(){...})
callback, it lags behind one url!
It seems to work fine when using Meteor.defer(...)
Tracker.autorun(function () {
Router.current();
Meteor.defer(function () {
window.parent.postMessage({'setPath': location.pathname + location.hash}, '*');
});
});
Problem is, I don't know why... Regardless, the above script works perfectly, and will be included in the next Brainstorm release. My meteor-fu is really rusty, as I haven't really used it for over a year.. Perhaps you can shed some light on why the above code works? @paulproteus
I think the reason is that location
is set to the previous URL -- Router
hasn't actually updated the browser yet, and the browser is in the middle of navigating.
Perhaps you can make this work by doing:
if (path) {
window.parent.postMessage({'setPath': path}, '*');
}
but does path
contain the full path (/a/b/c
) as well as the #...
(hash) component? That I don't know.
Thanks so much for looking into this, @Azeirah !
@paulproteus Nope, path doesn't contain the full path. There's Router.current().originalUrl and Router.current().url. Both look like "/board/whateverboard"..
Steps to reproduce:
/note/...
Expected behavior:
Actual behavior:
Fix:
Add something like this to the HEAD element, to synchronize the app's current URL with Sandstorm:
https://gist.github.com/paulproteus/99373ffce3c277bf6ec2
Also note - in the future, I hope Sandstorm can make this issue go away by e.g. automatically running JS like this to synchronize the location. But since it's needed right now, I thought I should alert you to it.