Link to part of the Blazor WASM page
P粉726234648
P粉726234648 2024-03-29 20:37:48
0
1
400

How do I link to a section of a Blazor WASM page?

Documentation.razor code:

@page "/documentation"
....
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>Groups</th>
            </tr>
        </thead>
        @foreach (var group in groups.Where(g => !string.IsNullOrEmpty(g)))
        {
            <tr><td><a href="#@gIndex">@group</a></td></tr>
            gIndex++;
        }

        <tr><td><a href="#@gIndex">Others...</a></td></tr>
    </table>

The above code creates a list of groups with hyperlinks as shown below:

/#0
/#1
/#2
/#3

However, when I click on the links, they route me to the root of the web application rather than being part of the current page, like

/documentation#0
/documentation#1
/documentation#2
/documentation#3

If I go to /documentation in the browser and append the sections manually, the browser does the appropriate redirects.

I tried hardcoding the route like a href="documentation#@gIndex" but that didn't do anything.

Any ideas how to get a hyperlink to a section on the same page to work?

P粉726234648
P粉726234648

reply all(1)
P粉729518806

This bug was raised a long time ago, please focus here: Hash routing to named elements 一个>

Try changing the link as follows:

@group
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!