Create Subpages within an Anvil Web App "/"

What I’m trying to do:

Hello, I want to create subpages for my web app which show up as different sub-URLs. I have a custom domain, let’s call it my_domain.com. I’ve linked my purchased my_domain.com to my anvil app. I know I can also create sub-domains, such as “sub_domain1.my_domain.com”. However, I want to be able to open different forms within my anvil app and have the URL of the site change from “my_domain.com” to “my_domain.com/sup_page1”.

For instance, I may have an “About” section in my website. Thus, I would like to have a “Home” page for “my_domain.com” and I’d like an “About” page, and when I click on a button within the app which opens either my home_page form, or my about_page form, I would like the URL to update to “my_domain.com/home” or “my_domain.com/about”, rather than presently just remaining as “my_domain.com”, even though the form does successfully open.

What I’ve tried to do

Is this possible? I have so far tried searching the DNS of Godaddy - where the domain was purchased from, to see whether I can find an option for this. However, ideally, I’d like to not have to update the DNS every time I want to create a subpage nested within my website - i’d like for this to be possible on Anvil.

Lastly, if this is possible on the Anvil side, I’d like to be able to dynamically change the subpage contents that appear after the “/” in the “my_domain.com/{dynamic_contents}”, specifically for if I have separate users log into my app, I’d like their username to appear in the “dynamic_contents” section, such that I have “my_domain.com/{user_name}”.

Would appreciate any advice on where to look to make this happen - I’ve searched this forum and haven’t found anything yet that answers this question. Thanks!

Welcome to the Forum!

And thank you for using Search! You’d be surprised how many visitors overlook it.

You can find some foundations under Navigation. Beyond that, I suggest a Search for “Hash Routing”, e.g.,

https://anvil.works/forum/search?q=Hash%20Routing

I haven’t used it myself (yet), but it comes highly recommended. Its developers and users are here on the Forum, as you’ll see from the Search results.

2 Likes

I think the only way you could do the subdomain.domain.com method is to split your app into multiple anvil apps with the same User system and then use link components to navigate between those pages. Then for the subdomain.domain.com/other_params bits you can use the anvil-extras routing pretty effectively.

The bad news
Anvil crates apps, not sites.
You can’t have “my_domain.com/home” or “my_domain.com/about”.
You can’t have Google indexing the home page or the about page.

The mildly good news
There are people in this forum that describe a way to generate pages in a site that can be indexed by Google, or that use http endpoints to generate indexable urls.

It is possible, but I’ve never done it. I think it’s too much trouble to get a suboptimal solution.

The very good news
I use other traditional tools to create a site with “my_domain.com/home”, “my_domain.com/about” and other indexable pages, and Anvil to create the apps I need. The pages in the site are indexed by Google and have either links to apps, or embed the apps in an iframe.

Each app has its own subdomain, for example “crating.my_domain.com”, “shipping.my_domain.com”, etc.

Each app uses the routing module of Anvil Extras, so I can have pages like:

  • crating.my_domain.com/#define?client=xxx&truck=yyy
  • crating.my_domain.com/#report?client=xxx
  • crating.my_domain.com/#search?client=x

Those urls can’t be used by Google, because Google ignores everything after the #.

But they allow to use the back and forth browser buttons, to create bookmarks to specific clients or crates or even to the search page with some search terms.

This gives me the best of the two worlds, an SEO friendly site surrounded by powerful web apps that can be navigated with the browser bookmarks and back and forth buttons just like any other site.

2 Likes

While you cannot create a subpage at root directory, you can create subpages like “example.com/_/api/page1

Then you can return an HTML file at that URL but unfortunately not an Anvil App (there is a hack for doing that too but it has limitations like server calls wont work)