https://github.com/sql-mistermagoo/prerendercomponent
Provides an IsPreRendering CascadingValue to Razor Components projects.
https://github.com/sql-mistermagoo/prerendercomponent
Last synced: 11 months ago
JSON representation
Provides an IsPreRendering CascadingValue to Razor Components projects.
- Host: GitHub
- URL: https://github.com/sql-mistermagoo/prerendercomponent
- Owner: SQL-MisterMagoo
- License: mit
- Created: 2019-03-12T00:22:12.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2020-06-15T16:20:12.000Z (about 6 years ago)
- Last Synced: 2025-03-30T20:11:08.964Z (about 1 year ago)
- Language: C#
- Size: 239 KB
- Stars: 10
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PreRenderComponent
Provides a DI Service and/or a CascadingValue exposing whether the app is in PreRendering or not.
## Usage
Install the nuget https://nuget.org/packages/PreRenderComponent
### Add the service (Required)
Add the service to your startup Configure method
This component has a dependency on HttpContextAccessor, so also add that.
``` CSharp
services.AddHttpContextAccessor();
services.AddScoped();
```
Consume the service wherever you need it (unless you want to use the Cascading Value component)
``` HTML
@inject PreRenderComponent.IPreRenderFlag PreRenderFlag
@if (PreRenderFlag.IsPreRendering)
{
Pre-Rendering
}
```
### Cascading Value (Optional)
Wrap the Router component in PreRenderCascade in the App.razor file
``` HTML
Sorry, there's nothing at this address.
```
Consume the CascadingValue in your own pages/components
``` CSharp
@if (IsPreRendering)
{
Don't Click me
}
else
{
Click me
}
@code {
[CascadingParameter(Name = "PreRendering")]
protected bool IsPreRendering { get; set; }
}
```