You could apply dynamic classes on the sidebar → so that on entry it'll be closed.
However, like Yehoshua said, it's probably better to use a NanoFlow as there is a specific action meant for that!
My recommendation would be to make a general sub-nanoflow that calls this action, in which case you can give it arguments too (if it's opened → close it or vice versa) before navigating to the called page!
You have a “toggle side bar” action inside nanoflow, so it’s probably way more easy to use a nanoflow