An open API service indexing awesome lists of open source software.

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.

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; }
}
```