Anvil Extras - Mixing Hash Routing and Navigation - Which one takes over?

Hi,

I’m trying to use the anvil-extras Navigation together with the Hash Routing navigation method.
I use the Navigation module for generating the menus dinamically, and I want to display the Form titles using its functionallity, in order to display a different title for each form in the Title slot of the template form (the one that holds the menu).

Here is what I’ve done:

I started with the Hash Routing only. Everything worked ok.
Then, I introduced the Navigation module, and made the required changes.

At this point I’m not sure which module is in fact taking care of the navigation, because I commented the nav_click event, so the Hash Routing is not being called directly anymore. However the navigation is happening. So, that makes me think the Navigation module is taking the task. But the Navigation module still needs the @routing.route from the Hash Navigation, to be present. Otherwise it does not work.

So, I’m confused about how this is working at all, because per documentation:

In order for a form to act as a target of a menu link, it has to register a name with the navigation module using a decorator on its class definition.
For example:
@navigation.register(name=“about”, title=“About”)

And I’m not using @navigation.register anywhere.
I tried using it, because I wanted to display the Title, but it completely ignores it.

So, I’m clearly missing something here. What could that be?
In summary, how is this navigating to the target forms if I haven’t registered them with the Navigation module?, and why when I use the @navigation.register, it ignores it and so the title functionallity?

Here is the sample app.

You will see the menu items defined in the visual designer, which are the ones I used for working directly with the Hash Routing + nav_click event.
And also the dinamically generated links using the Navigation menu, which are the ones that are working now.

Thank you !!!

The navigation module basically does what you were doing with the click event handler. If you tell the navigation module you are using hash routing it will do set_url_hash(sender.tag.target) when one of the navigation links is clicked.

Note you don’t want the leading slashes in your targets ("/about" should be "about").

With questions like this it’s often better to ask on the anvil extras GitHub discussion page

anvilistas/anvil-extras · Discussions · GitHub

The source code is available there, which can also help to clarify some of these questions. The navigation module isn’t that many lines of code and you can get a feel for what is going on.

Ok, the navigation part is clear!
Still does not explain why it works without registering the forms (unless it is not really necessary, in which case perhaps the docs need an update), and also why the title is not displaying at all?

The /about was because I was also trying for the case I have more than one Template that could call this form, or to restrict the calling of this form from just one Template. (still work in progress)

As you suggested, I’ll move the question the the Github discussion page.
Thank you!

Registration is probably only necessary for the navigation without hash routing. Since the navigation module would need to know which form to load when navigating. Whereas when using hash routing the navigation module has all the information required to navigate based on the targets within the call to build menu.

Well, it might be so.
I did a quick test, and eliminated the hash routing.
What happens is that the Navigation module stops working. And it displays this error message:

#routing: routing is not ready or the template has not finished loading: queuing the call None

It seems that they are both needed.
Per docs.

Note - since this example includes hash routing, it also requires a decorator from the Hash Routing App on the Main class.

So it still remains a mistery to me, why it does ignore the registration and the title.

Solved by stucork and meatballs, here: