Home > other >  Can the google crawler detect an url state change made by my angular app?
Can the google crawler detect an url state change made by my angular app?

Time:11-18

Say I have an angular app that defines the following path.

  { path: ':lang/journal/:id/:title', component: JournalComponent, runGuardsAndResolvers: 'always', resolve: {journalOverview: JournalOverviewResolver} },

The resolver JournalOverviewResolver makes a request for the page details. This http request really only needs the :id url parameter to get the desired response. This means that visiting the url: www.mywebsite.com/en/journal/12/the-actual-title-of-journal will load the page, but the url www.mywebsite.com/en/journal/12/dslfjslishshsdkljf will also lead to that same page.

I don't want to allow this. Only one url can be valid. So when the last path segment is different to the actual title of the journal i want the app to automatically change the url thats in the browser. I use the following for that.

import {Location} from '@angular/common'

constructor(private location: Location)
{
}

changeCurrentUrl()
{
    let parts = window.location.pathname.split('/');
    parts[parts.length - 1] = actualJournalTitle;
    this.changeUrl(parts.join('/'));
}
 changeUrl(url: string)
 {
    this.location.replaceState(url);
 }

This works great but i am wondering what kind of impact this has on SEO. If the google crawler crawls an url with an invalid title path segment, and the path segment is automatically changed by the app, will the google crawler pick this up? Or will the google crawler still see the invalid url as the actual link to that page?

I know that this website (stackoverflow) also automatically changes the url of a link if its invalid. Just take this SO question for example: https://stackoverflow.com/questions/32939620/this-is-not-the-correct-title. When visiting that page the last part is automatically changed into password-finder-something-like-bruteforce-java. I assume the website simply changes the url instead of redirecting. But does the google webcrawler pick something like that up?

CodePudding user response:

Google eventually treats JavaScript changes to the location when the page loads the same as a server side redirect. Using location changes to canonicalize your URLs will be fine for SEO.

The same caveats that apply to all JavaScript powered pages apply to this case as well:

  • Google seems to take longer to index pages and react to changes when it has to render them. JavaScript redirects may no be identified as redirects as quickly as server side redirects would be. It could take Google a few extra weeks or even a couple months longer.
  • Google won't see any changes that happen in response to user actions such as clicking or scrolling. Only changes that happen within a couple seconds of page load with no user interaction will be recognized.
  • Related