简体   繁体   中英

ASP.NET Javascript Services Server Side Render Specific Routes

With Microsoft's ASP.NET Javascript Services is it possible to pick and choose which routes get rendered server side?

I need marketing pages like the home page to get rendered on the server for SEO, but the web app pages to only be rendered on the client.

I am using react, react router and asp net core 2.0.

Use asp-prerender-* in a view, as described here

https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.SpaServices#server-side-prerendering

For example, in your cshtml:

<div id="my-spa" asp-prerender-module="ClientApp/boot-server"
             asp-prerender-data="new {
                IsGoldUser = true,
                Cookies = ViewContext.HttpContext.Request.Cookies
             }"></div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM