-
This is a feature request. My use-case is that I have a menu to select items from a route I can of course do with I am currently using The only issue with that is it would be nice if the server-side could update the location in the browser if the user wishes to bookmark that page. Basically the ability to send data to the browser |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
Sorry I just realised this should be over in the Feature Request section of Discussions. |
Beta Was this translation helpful? Give feedback.
-
Hm i am not sure if i want such a feature. Let's say there was It adds a whole new dimension to debugging as well. If a user states "i have a problem with the view behind /foo/bar/" you can't just look in the routing table to find the broken view. Seems like a lot added complexity to save a few redirects. Also in my experience it's a bad idea to tinker with the browser history for the most part. It gets confusing very fast, therefore i tried to emulate the behavior a siple flask app would have (and I needed 3 attempts to get that right) If you really want that you ca, add that as a custom feature to your frontend template. I can give you a code example if you want |
Beta Was this translation helpful? Give feedback.
-
@mwx23 I changed the label to Q&A, because it's not a feature request anymore :) |
Beta Was this translation helpful? Give feedback.
-
Just an update on my implementation for those interested. Also this solution means you should be able to run other DOM methods (completely untested, buyer beware...). // frontend.js
lona_context.add_message_handler(function (lona_context, raw_message) {
if (!raw_message.startsWith('custom-message:')) {
return raw_message;
}
let [namespace, method, ...args] = raw_message.split(':');
let cmd = `${method}(...args)`;
let res = eval(cmd);
// serialise res and send it back to the server
// lona_context.send(`custom-message:${serialisedRes}`);
}); Then in my View: self.send_str(f'custom-message:window.history.replaceState::my new tab title:/my/updated/route') Absolutely loving how easy |
Beta Was this translation helpful? Give feedback.
Just an update on my implementation for those interested.
Also this solution means you should be able to run other DOM methods (completely untested, buyer beware...).
Obviously more care needs to be taken with the deserialisation from python. Perhaps a more formalised JSON structure.