-
Notifications
You must be signed in to change notification settings - Fork 518
Add simpler API for invoking prerendering without using tag helper #607
Comments
Thank you for looking into this @SteveSandersonMS ! 💯 💯 Also for those wondering what the use-case for this is: Since we're allowing .NET (MVC) to have control over the overall Being able to manipulate Your example looks like it would be perfect for this!
One last question, would this be an alternative to the way we're currently doing things, or would all the templates need to be changed in this way? I feel that ideally they might as well all change, because eventually everyone will get to the point where they realize they need to update the Title / etc. (On the Angular side) I have a way of extracting the title/meta data from the serialization, but I'm going to look into making it even easier & cleaner. Ideally it'd be great to have Universal do something like this, I brought it up that normal meta manipulation won't work with .NET for the reasons above, so I'm hoping I can somehow convince them to add this in there.
|
@MarkPieszak Is there any reason not to switch to code you provided in last post? Only thing that comes to my mind is asp-append-version attribute that is used for cache busting. |
The code will actually be slightly similar to the above :) Of course some of those APIs have changed in Angular 4.x since I wrote that, but so far I have it working, and am able to extract out styles (to be placed in the correct location), Title, and only place in the correct Html from the serialized application (instead of the entire We're still in beta, so I'm trying to work everything out and communicate back to the Core team to make sure everything works smoothly. II should be updating it in my repository once everything is ironed out more, I'm also going to eventually abstract out some of the logic so it's much cleaner in the We're getting there though! 😄 @hheexx |
Thanks @MarkPieszak , I hope you can commit something around RC time :) |
Not a problem totally understand! |
Just on a side-note: I'm using the code at the top of this thread in my I had to add
to make redirects in my react-router work:
I also had to add code to make the react-cookie work again: (HomeController)
(Index.cshtml)
The code in boot-client (ReactReduxSPA) also doesn't take care of the cookie options, e.g. path. |
I've developed an web application built using ASP.NET Core Web API and Angular 4. My module bundler is Web Pack 2. But I would like to use server side prerendering. I would like to add metatags into head:
Is it possible to do without "ViewData"?` |
You receive rendered html string from node.js. |
@hheexx ok, how can I add meta tags from controller to html page? |
html page is in a string so you need to find a way to find the right spot and insert meta in. |
Why is this so poorly documented? I can't find anything online explaining exactly how to use Prerenderer directly except this github issue. |
You can see an example of it in action here @mryarbles |
@hheexx I have a way to send data to plain html. And this data correctly is added to metatags:
However, Search engines, Facebook, Twitter does not show my images when I try to post news at Facebook, Twitter or other social nets. I've explored why it happens and the reason is that SEO does not run JavaScript code. So when I post I do not see images. I cannot use tag helper and ViewData as I've created ASP.NET Core Web API project and I do not have any ".cshtml" page. |
There's now a new API for this. It looks extremely similar to the proposal in this issue. Sample usage: 94fc84a#diff-ac9fabb76766dea5d503c5a5387e88e4 Further docs will come later. This will be included in version 2.0.0 of the SpaServices package. |
Although the
asp-prerender-module
tag helper is usually the most convenient and natural way to invoke prerendering, there are some cases where you'd want to do it from controller code, or from a code block in your Razor page. For example, you might want to receive back additional custom data values from prerendering, and then maybe use them to set the page title or similar. Or you might want to change how theglobals
values are serialized and delivered to the client.Currently it is possible to do this by invoking
Prerenderer.RenderToString
directly. However it's inconvenient, because you have to duplicate some non-obvious logic from the tag helper. For example, to run prerendering from controller code, currently you need something like this:We should consider migrating this logic out of
PrerenderTagHelper
and into some new DI service class thatPrerenderTagHelper
starts using. Then developers will be able to grab instances of that new service class and do custom prerendering much more easily. Ideally, you'd be able to do something like this directly in a Razor view:There could be an options param for overriding things like the request URL, timeout, etc., but by default it would use values from the context automatically like
asp-prerender-module
already does.The text was updated successfully, but these errors were encountered: