Google indexing with route decorator

Okay, just to confirm that I am understanding correctly how to create a Google searchable description of what’s on a given ‘page’, please let me know if I’m understanding your directions:

Say my goal is to allow Google to “see” my landing page, including to understand both the URL and some simple metadata about the page.

In the code for my landing page, do I enter something like:

anvil.server.route(“/home”)

I assume I place this under the init section. Then add on the server page I add something like:

@anvil.server.route(“/home”)
def home(**p):
return {“description”:“This page includes a definition of taxidermy”}

So, if I’m understanding it correctly, Google can hit the page, and it will then receive (via the server) this metadata information with both the path and the description of the page. Is this correct?

Thanks,
Drew

If you need indexing for just the landing page (In Anvil terms - your startup form), you don’t even need routes. Requesting indexing for your website on Google Search Console should do just fine.

Routes are useful when you have other forms that also require separate indexing.

1 Like

Thank you. Of course, that’ll be my next task, using routes on other forms :wink:

Best,
Drew

Okay, now I am trying to add the routes for my other forms that also require indexing. I understand that the startup form will not need the route added in order for Google to index it. My other forms are in the following structure: there is a form that serves as the page frame that holds the footer etc., and then a form (“main panel”) gets swapped out. I need for Google to index a URL for the combination of the page frame and the main panel form.

I’m confused on some points.

  1. In the Forum post (Serve anything, anywhere on your domain, with @anvil.server.route()), there is a discussion of responding to a path within the app’s domain with anvil.server.route

I assume that goes in the server page. I know how to point to an anvil.server.callable from a form, but is pointing to an anvil.server.route done the same way? Do I say something like anvil.server.route(“/dictionary”) from my form (to point to the decorator on the server page)? Because doing so throws an error (anvil.server has no property route). And further, why would I only want to use the anvil.server.route ? If I understand correctly, that only allows, say, Google to index that page. But it does not create a URL that others could use to reach that page from, say, a Google search listing. Am I correct in this? So, then, of what practical use is anvil.server.route ? Okay, I could imagine a practical user might be to return a description meta tag or somehow reveal this to a Google spiderbot (as an example), but I am not sure how to do this from available documentation.

  1. Okay, again as discussed in the Forum post (Serve anything, anywhere on your domain, with @anvil.server.route()), if I want to serve a human-accessible UI on a particular URL (which I want to do, if only from listings provided to human users of a Google search), it is clear that I will need to return a FormResponse object. Okay, but again, how do I call that from a form? And how can I call it from my particular form, such that when a human uses the resulting URL. it will create a page that will include both my outer from for the page as well as the interior (main panel) form? I believe I understand how to pass an argument into the Form Response object from the documentation now available. But I am not sue how to do the rest.

As always, I am very grateful for the expertise of this community. I’m making progress with my site (instareport.us) and I would not be here without your expert help. Thank you in advance!

Regards,
Drew

1 Like

You don’t need to do anything in the form to have it respond to the URL:

Server Code:

@anvil.server.route("/dictionary")
def dictionary():
  return anvil.server.FormResponse("DictionaryForm")

and then you can add any necessary args or kwargs to the Form response that your form needs.

The only thing I do differently in my server/forms with the new routing is I tend to do the calls to the database within the router function itself rather than anvil.server.call in the form, but that is up to you.

Then you can just test your router with a debug environment link. See my post where I figured this out with help from Meredydd:

See here for the documentatiion:

3 Likes

Thank you. I confirm that I can test my subpages fine using this excellent debugging tool :-). I think that this means that I am probably fine also with at least allowing Google to locate and identify pages even without use of separate meta tags for the individual subpages, although some of the other search engines may have some difficulties unless we can add the meta tags easily, at least based on what I’m reading.

1 Like