Hi all, I hope you are doing well. First off, I'd like to say thank you for this amazing project! I already have a few client projects setup using Inertia and Forge and the development experience is excellent.
Whilst working extensively with this framework, I've run into an issue which I'm hoping has a trivial solution.
I'm using withViewData to pass in page titles and meta descriptions as recommended in the docs here. Example on my blog page:
return Inertia::render('BlogSingle', [
'blog' => $blog
])->withViewData([
'pageTitle' => $blog->title,
'metaDesc' => $blog->excerpt
]);
Then I am rendering the data in my main app.blade.php:
<title>{{ $pageTitle ?? '' }}</title>
<meta name="description" content="{{ $metaDesc ?? '' }}">
The problem is that when navigating through the site to reach this page (and any page for that matter) the title and meta descriptions aren't being updated. If I refresh any particular page then the title and meta are updated, but navigating throughout the site doesn't trigger an update.
Is there a different way I should be doing this? Thank you in advance for any advice you can give!
Hey @Ollie1700, thanks so much for your interest in this project!
So, really the root template data isn't that useful. It's only used for the initial render of the page. Some people use this for SEO benefits (to have the title and meta information set), but that's really the extent of the withViewData() feature usefulness. It's good to keep in mind that Inertia.js is client-side rendered, meaning it's not well suited to public websites where SEO is a concern.
Really, what you want to do is set the page title when you navigate from page to page. You can find instructions on how to do that here.
I hope that helps!
Hi @reinink , thanks for your response!
Thank you for pointing me in the right direction, Vue Meta works great 馃槂
it's not well suited to public websites where SEO is a concern
Could you expand a little on this point? As far as I understand, crawlers can still navigate the site as if it were a "traditional" setup. Apart from small hiccups like this like updating meta information, I would think that crawlers have no trouble navigating an Inertia site and mapping it out? (since links compile down to a tags with fully resolved hrefs)
My knowledge is limited here, so I'm just looking for your insight on this point!
Thanks again!
Hi @Ollie1700,
Basically, you're right that _some_ crawlers can index Javascript-heavy apps just fine these days, but so far it's only the 'big' ones that are able to do so, and even then it can take them up to a week or longer to properly index your sites.
What this means, is that if you have an active website with things like by-the-hour news, this obviously wouldn't really work out well for SEO, as 'being the first' means everything in those kinds of situations.
Workarounds to this problem involve using server-side rendering with tools such as https://github.com/Juhlinus/depictr/, but unfortunately setting those up isn't the most straightforward process.
Hope this helps!
Thanks for your insight @claudiodekker - much appreciated!
Most helpful comment
Hey @Ollie1700, thanks so much for your interest in this project!
So, really the root template data isn't that useful. It's only used for the initial render of the page. Some people use this for SEO benefits (to have the title and meta information set), but that's really the extent of the
withViewData()feature usefulness. It's good to keep in mind that Inertia.js is client-side rendered, meaning it's not well suited to public websites where SEO is a concern.Really, what you want to do is set the page title when you navigate from page to page. You can find instructions on how to do that here.
I hope that helps!