-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use router navModel to inject metatags server-side? #604
Comments
@Alexander-Taran Yes, I'm already on that thread, but rquast was going a different route (tying data statically to each route via the router config) whereas I need the data populated dynamically depending on API data. I haven't been able to find any way to do this anywhere online with Aurelia. It seems like it's no big deal in the Vue (vue-meta)/React (react-helmet) camps, so I'm trying to figure out how exactly to do it in Aurelia. |
Just so I understand this correctly, you want to:
To rephrase: metadata goes from the server to the client, is assigned/distributed on the client, which the server then needs in order to pre-render a page that isn't actually loaded from the server since you're navigating to it from the client side. I must be misinterpreting you somewhere but that's how I'm reading it. Please correct me if I'm wrong :) |
@fkleuver Using SSR, running Aurelia server-side, the requested page/route is rendered with metatags that are dynamically populated by whatever route is requested. Example: Aurelia should render the user view, then takes the dynamic value "JohnDoe", sends to the API, pulls appropriate information about that page, then adds it to the Then it gets rendered server-side in HTML before the client-side Aurelia begins. This is a mandatory need for my app, as I have thousands of individual pages with SEO requirements AND must be deep-linkable via OpenGraph (Facebook) and Twitter. JSON-LD client-side isn't good enough, and even Google's JS rendering isn't good enough. Neither of those options are supported by Facebook or Twitter (or other future social share use cases). |
Ah that makes sense. I guess we wouldn't need to do anything specific in Perhaps accompanied by some SSR configuration to tell SSR on which property it needs to look. Then it can't accidentally do unexpected things when people use a particular settings property for other purposes that just happens to match the ( In any case not much (or nothing at all) can/should be done in |
@fkleuver Well, look at vue-meta's implementation:
I would think you could pull the dynamic route slug off the route, use isomorphic-fetch to send it to the API to get back the metadata needed, and then that "metadata" object is injected into the head before Aurelia renders the page. The thing is, I can't use route.config, because that would be static only. Rquast's "transformer-step" code is close, but it's pulling from the route.config for the data, whereas I just need it to fetch from an API instead. The aurelia-router already has a title property, so I thought it made sense that it should potentially have access to populate the entire |
The "ssr-transformer":
https://gist.github.com/rquast/a9cbc0551a48d10e83b2ad899b293c77 |
The thing is that the page title can changed via That's a key difference that makes |
So, something like:
? How exactly would we be able to add tags to the HTML via the ssrProperties property? How would the ssrProperties object parse the incoming data? I really appreciate the discussion and assistance, as I know there must be many developers in the same boat with SEO requirements for their apps. |
Is there a way to create a method like routeConfig.navModel.setTitle(), but for adding meta tags to the head for SSR?
Essentially, I need a way to add html meta tags server-side (description, OpenGraph, Twitter, etc.) for each route - but it needs to be dynamic and dependent entirely on API-retrieved data.
So something like (not real code, just approximate):
The text was updated successfully, but these errors were encountered: