Why Blazor style isolation not working with routing?

134 Views Asked by At

When a component is opened by navigating to its route, style isolation does not work, the styles are not applied, but if you add this component to another, then the styles work. I can’t understand if this is a feature of the framework or my mistake

1

There are 1 best solutions below

0
On

When a component is opened by navigating to its route, it's already a component within another component, so it will work exactly the same as your second case. So I think the answer is "my mistake".

As you've provided no code, here's a very simple demo page showing it working in a routed component.

Test.razor

@page "/"
<h3 class="makemered">Test</h3>
@code {
}

Test.razor.css

.makemered {
    background-color: red;
    color: white;
}

enter image description here