Add SEO to Your Router

This article explains how to configure SEO for your router pages. There are two parts to setting up the SEO:

  1. Create meta tags for Google to learn about your pages.
  2. Create a sitemap for Google to use to find your pages.

Step 1 | Set meta tags for router pages

You set SEO meta tags for your router's pages in the router() function in routers.js:

  1. Within the router() function, create an object that contains your desired SEO settings. This will become the HeadOptions object that you pass to the router page.

    Use the provided sample code in the router() function as a starting point:

    Copy

    The example object contains several properties that are set using the data it retrieves in the router() function, including the following:

    • The title property, which contains the page’s SEO title.

    • The description property, which contains a short description of the page’s content.

    • A noIndex flag, set to false. This tells Google that it should index your page.

    • Additional meta tags contained in the metaTags property. You can add meta tags to this property.

    Keep or remove these properties, and add your own as needed.

    Note: The HeadOptions object can also contain a keywords property, but Google ignores your site's keywords.

  2. Once you’ve created your HeadOptions object, pass it to the ok() function as the third parameter. This object is then sent to the router page so that Google has SEO information for it.

    This sample code shows an example of passing the HeadOptions object defined above to myRouter-page:

    Copy

Step 2 | Create the sitemap for your router

To add your router pages to your sitemap, do the following:

  1. In your router’s sitemap() function, create a WixRouterSitemapEntry object for each URL the router can possibly route to. Use the sample code added to your first sitemap() function as a starting point:

    Copy

    Each WixRouterSitemapEntry in the example includes the router page’s URL, title, and name. The example code groups them into an array.

  2. Return all the sitemap entries to create the router sitemap. Again, you can follow the example in the sample code:

    Copy

Step 3 | Check your router sitemap

To ensure that your sitemap is working properly, you can get the sitemap from your published site:

  1. In a web browser, go to your published site's URL and append /sitemap.xml to it.

    For premium sites, if your site's published URL is: https://mysite.com, go to: https://mysite.com/sitemap.xml.

    For free sites, if your site's published URL is https://username.wixsite.com/site-name, go to https://username.wixsite.com/site-name/sitemap.xml.

  2. Check that the sitemap matches the layout of your router pages.

See also

Did this help?