HashRouting and multiple main_router

I’ve been using the HashRouting module developed by @stucork and it is a brilliant add-on to the Anvil ecosystem.

I was wondering if HashRouting can support multiple main_routers.

I have a MainForm with the Header bar and the Side Navigation and another Form that is displayed without the Side Navigation.

What would be the best way to handle this with HashRouting.

Thanks
SS

Awesome! please it’s working out.

Good question. I’ve not tried this, except to load a LoginForm that doesn’t have any routing behaviour.

I think just using standard open_form('SecondaryMainRouter') will work (with some limitations).

this will make SecondaryMainRouter the MainRouter and it should sort of behave as you would expect…

except that things will get tricksy if you use the back button to load a route that is not part of SecondaryMainRouters known routes. :exploding_head:

If there are no differences between the route Forms of PrimaryMainRouters and SecondaryMainRouter then there should be no issue.

If there are differences then you would probably need to customize the MainRouter on_navigation function…

pseudo code that might work…

def on_navigation (self, **nav_args):
  if nav_args['url_pattern'] is from the OtherMainRouter:
    open_form(OtherMainRouter)
    # this probably won't work ... but maybe

If you produce a minimum code example with a clone link, I would be happy to take a look.
and if necessary include the feature if it can’t be hacked.

Hi @stucork

I see where you are going with the example.

If I’m not mistaken, loading the secondary router with open_form(SecondaryMainRouter) essentially disables the routes on the URL right?

The scenario that I’m trying to address is:
URL - /Workspace (uses the Main Router with the side bar)
URL - /Projects (uses the Secondary Router without the side bar)

So the need for the secondary router is inside the users workflow, not something as discrete as Login which happens prior to the users’ workflow.

Thoughts?

What about having a single main_router and using the on_navigation function… just hiding the sidebar column panel depending on the url_pattern And changing anything in the address bar that needs changing…

Yes, I’m going down that path right now where given the url_pattern, I completely hide the sidebar and the hamburger nav and enable it by adding the following JS function in the standard-page.html file and calling it using the anvil.js.call_js() method.

function disableSidebar() {
  	/* hide the hamburger nav */
    var ln = $('.structure > .app-bar > .sidebar-toggle');
    ln.css("display", "none");

    /* hide the sidebar itself */
    this.hideSidebar();
  }
  
  function enableSidebar(){
    /* show the hamburger nav */
    var ln = $('.structure > .app-bar > .sidebar-toggle');
    ln.css("display", "block");

    /* show the sidebar itself */
    this.showSidebar();
  }

The above does the trick as all I needed to remove was the sidebar.

Thanks for your input.

SS

2 Likes