We have an application with multiple forms on it. We want to redirect a user from another application (might be an Anvil application or an external application) to a specific form of Anvil application but I am not finding a way to do that.
Is there a standard way of doing this? Please help.
1 Like
Anvil apps are Single Page Apps, so you can’t use the url as you would on other apps, but you can get the query string (the part after the #
) as a dictionary. See the docs here: Anvil Docs | Navigation
The routing module of Anvil Extras builds on that to create a nice navigation system.
1 Like
Use get_url_hash().
The followng code creates 3 unique URL links to 3 separate subform panels of a startup form named Home_page. The 3 sub-forms are named:
about_panel
getting_started_panel
more_info_panel.
You can access the 3 pages directly at the URLs:
https://yourappname.anvil.app/#?page=about
https://yourappname.anvil.app/#?page=getstarted
https://yourappname.anvil.app/#?page=moreinfo
from .about_panel import about_panel
from .getting_started_panel import getting_started_panel
from .more_info_panel import more_info_panel
class Home_page(Home_pageTemplate):
def __init__(self, **properties):
self.init_components(**properties)
urlhash=get_url_hash()
if dict=type(urlhash):
if urlhash['page']=='getstarted':
self.content_panel.add_component(getting_started_panel())
elif urlhash['page']=='about':
self.content_panel.add_component(about_panel())
elif urlhash['page']=='moreinfo':
self.content_panel.add_component(more_info_panel())
else:
self.content_panel.add_component(home_panel())
To be clear, this works in conjunction with sidebar menu links that look something like this:
def link_1_click(self, **event_args):
self.content_panel.clear()
self.content_panel.add_component(about_panel())
def link_2_click(self, **event_args):
newpage=getting_started_panel()
self.content_panel.clear()
self.content_panel.add_component(newpage)
newpage.label_1.scroll_into_view()
def link_3_click(self, **event_args):
newpage=more_info_panel()
self.content_panel.clear()
self.content_panel.add_component(newpage)
newpage.label_1.scroll_into_view()