Hash Routing with Templates - Fail to make it work with some variation from the original

Hi,
I’m trying to create an application that:

  1. Starts in a landing page (that currently just has a button to initiate)
    Pressing that button takes you to a Public Area with some menu options and a login button.
    This works fine.

  2. Once you log into the application, you should be taken a different page (Template) that will have the menu options according to the area defined for your user, and the Forms corresponding to that options. The area in wich you work is an attribute of the user (unidad) and is taken from the users table. (Marketing is the only one implemented so far)
    This is the part that is not working fine

    3 Once you logout you should return to the landing page
    This apparently works fine

For achieving this I:

  1. Defined several Templates for Hash Routing to different groups of Forms mimicking the Hash routing with templates example. Mainly because the behavior I intend to have is very similar although it has some differences.

  2. Each Template corresponds to a different area, and it has several associated Forms, and a different menu.

  3. Once you login you should be directed to the corresponding Template that will call the Home Form for that Template (and not the Home of any other Template ), then generate and display the right menu for the user, that in turn will allow navigation to the rest of the Forms for that area.
    I’ve done it up to here, but it is not working fine, so the problems are probably here

  4. The menu is generated dinamically in each Template using Navigation module.
    This works fine.

Basically the problems start when I log in and try to navigate to the Marketing area (the only one I have defined so far, and the one the user belongs to). It then starts behaving oddly and unstable.

I’ve looked at the logs for the routing module when executing, and they show a behavior I can’t trace/understand. I’ve read the hash routing documentation but I can’t make a match for those error messages.

I think that the mechanism works well, and it’s me that have been unable to put the pieces in the right place and order.
Might be something related to the way I’m doing the navigation, or maybe some not so well defined decorators, but I’ve done many tries and can’t get it right.
The first thing you will probably notice is that the menu changes to the correct one, but the Home page does not corresponde to Marketing, and then when you click in any of the other links it crashes and returns to the Public Area??

Here is the application. In case you want to check the behavior, the user for loggin in is usuario@gmail.com and the pass is uSuario-1. This user belongs to the Marketing area. Anvil | Login

I’ll really appreciate any help in order to understand where I’m messing things up. At this point I’ve completely lost the North.
Thank you very much!!

Given that this is anvil-extras you probably want to ask this at the anvil-extras GitHub discussion page again.

Looking at the code the issue seems to be in your Home pages.

The public home page doesn’t specify a template. And since you want it to only be available for the public template you need to specify it.

You never imported the Marketing Home route to your app so it was never accessible.

These two changes should make it work.

Here’s a working clone with those two changes.

(You might need to change the user row to be able to login)

Hi, and thank you!
Well, it is still not working. It is throwing the same errors.
When I login it displays the Marketing menu, but as soon as I click any of those links (in this case redesSociales) it falls back to the Public menu, that is, it navigates back to the RouterPublic Template and does what you can see in the routing logs below, which is basically what I don’t understand.
The error that it throws is logical as it is calling a Form declared in the other Template, and so it doesn’t find it.
The problem is why it is navigating back to the Public Template?

I’m moving the whole conversation to the github discussion group, so that we can continue there.

#routing: setting url_hash to: '#Marketing', adding to top of history stack
#routing: navigation triggered: url_hash='Marketing', url_pattern='Marketing', url_dict={}
#routing: entering navigation level: 0
  #routing: checking templates and redirects
  #routing: changing template: 'RouterAreaPublica' -> 'RouterMarketing'
  #routing: loaded template: 'RouterMarketing', re-navigating
  #routing: navigation triggered: url_hash='Marketing', url_pattern='Marketing', url_dict={}
  #routing: entering navigation level: 1
    #routing: checking templates and redirects
    #routing: unchanged template: 'RouterMarketing'
    #routing: RouterMarketing.on_navigation() called
    #routing: loading route: 'Home' from cache
  #routing: exiting navigation level: 1
#routing: exiting navigation level: 0
#routing: navigation complete
          
#routing: navigation triggered: url_hash='/redesSociales', url_pattern='/redesSociales', url_dict={}
#routing: entering navigation level: 0
  #routing: checking templates and redirects
  #routing: changing template: 'RouterMarketing' -> 'RouterAreaPublica'
  #routing: loaded template: 'RouterAreaPublica', re-navigating
  #routing: navigation triggered: url_hash='/redesSociales', url_pattern='/redesSociales', url_dict={}
  #routing: entering navigation level: 1
    #routing: checking templates and redirects
    #routing: unchanged template: 'RouterAreaPublica'
    #routing: RouterAreaPublica.on_navigation() called
    #routing: no route form with: url_pattern='/redesSociales' url_keys=[]template='RouterAreaPublica'
              If this is unexpected perhaps you haven't imported the form correctly
  #routing: exiting navigation level: 1
#routing: exiting navigation level: 0
#routing: navigation complete
          
*LookupError: '/redesSociales' does not exist*
*at app/anvil_extras/routing/_router.py:302*
*called from app/anvil_extras/routing/_router.py:343*
*called from app/anvil_extras/routing/_router.py:267*
*called from app/anvil_extras/routing/_router.py:151*
*called from app/anvil_extras/routing/_router.py:151*
*called from app/anvil_extras/routing/_router.py:111*
*called from app/anvil_extras/routing/_decorators.py:36*
*called from app/anvil_extras/routing/_router.py:235*
*called from app/anvil_extras/routing/_router.py:140*
*called from app/anvil_extras/routing/_router.py:140*
*called from app/anvil_extras/routing/_navigation.py:54*
#routing: navigation triggered: url_hash='/acercaDe', url_pattern='/acercaDe', url_dict={}
#routing: entering navigation level: 0
  #routing: checking templates and redirects
  #routing: unchanged template: 'RouterAreaPublica'
  #routing: RouterAreaPublica.on_navigation() called
  #routing: loading route: 'AcercaDe' from cache
#routing: exiting navigation level: 0
#routing: navigation complete

Let’s move this to the anvil extra’s discussion page. There could be a lot of back and forth and it’s not all that relevant to anvil specifically