Need some help here.
So we are in process to take Blazor as our front-end framework but I am stuck on a very small thing.
First here is the requirement:
- We need a SSR website, where we can show the list of the products and their details etc. It should be SSR for the SEO purpose.
- We need a backend management app, on which we can build a backend app where users can add/edit/delete the products.
The thing we wanna build is
- On root URL, we need all the SSR content like www.example.com, www.example.com/product/xyz. All pages will be SSR. I believe we can handle this by making Blazor Web App (Server) and use the SSR interactive mode.
- The issue comes here. We want to access the backend web assembly app on the URL www.example.com/app. The app should be loaded when we call this URL and everything should just work under this app. Is this possible?
Any help or tutorial will be highly appreciated.
J
2
Answers
To achieve your requirements, here are some ideas:
Start by setting up a Blazor Web App project in Visual Studio. Ensure you enable interactive rendering per page or component. This configuration will allow you to leverage both Server-side rendering (SSR) and WebAssembly for specific components or pages.
Note: If project is created, you can change program.cs config to allow this.
This setup will create two projects:
The first proyect configured for
Server-side rendering
. This will handle all SSR content, such aswww.example.com
andwww.example.com/product/xyz
.A secondary project for
Client-side WebAssembly
(often ending with .Client), allowing you to render components as WebAssembly for dynamic or interactive parts.One layout will host the Server-side components and serve content rendered on the server, e.g., the pages under http://www.example.com/product.
For SSR components, you can add them to any layout without specifying a render mode explicitly—they will default to static rendering. For
If I read your requirements correctly, you should be able to do as you wish using the current Template.
Deploy a solution using the Blazor Web App template. Select Interactive Auto and Per Page/Component interactivity.
This makes:
Change Counter to this. It’s now
InteractiveWebAssembly
so we have no confusion, and the need to deal with both Server and WASM rendering of the page.Add this to
Home
andWeather
so you can see their render information:What you end up with is an application where
App
,Router
andLayout
are rendered on the server, and the Page content is rendering according to it’s setting. The WebAssembly SPA session remains active [once loaded] until you navigate away, or reset with an F5.There’s a Repo here: https://github.com/ShaunCurtis/SO79308298