If it is implemented well, it won't hurt SEO.
When all URL changes are done onclick
it might be tempting to no longer using <a href
links in your pages. However, doing that would make your pages uncrawlable. To implement the feature while supporting search engine crawlers your links would have to look like normal links in the source code but have an on-click that changes the page and prevents the default navigation. Something like:
<a href="/foo.html" onclick="showfoo(); return false;">Foo</a>
showfoo
would load the correct content into the page and using History.pushState()
to change the URL for the user without fully loading the new page. The return false;
prevents the browser from handling the href
on its own.
You would also need to make sure that if you type http://example.com/foo.html
into your browser, the correct page and content loads. Even when users don't navigate to that URL from within your website, you need to support search engine visitors that come into that URL directly.
JavaScript based navigation is often accompanied by entire pages built with JavaScript using frameworks like Angular and React. Building entire pages with JavaScript comes with its own set of SEO pitfalls. Only Googlebot is advanced enough to crawl such sites. Other search engines like Bing, Yandex, and Baidu won't be able to index your site at all. (That isn't necessarily a deal breaker because Google owns 90+% of the search market.)
However, even for Googlebot there are some gotchas:
- Indexing and updates take way longer. Google may take a few weeks extra to process your page and include it in the search index.
- Googlebot doesn't click anything, scroll the page, move the mouse, or otherwise interact with the page. The only content that Googlebot sees is the content that shows up when the page is loaded. Any content that appears only after user interaction will be ignored.