首页 > 解决方案 > 在 NODEJS 中使用超链接和按钮更改路线的正确方法是什么?

问题描述

我需要更改某些页面内的路线,然后我从后端跳出并在按钮的点击或超链接href中自动生成值...

注意:我从后端传递值,因为我使用参数等来实现这些值。

我正在使用 NODEJS + EXPRESS

<!-- EM CONSTRUÇÃO -->
<header>
    <nav class="navbar navbar-expand navbar-light bg-lilas-2 fixed-top <%= informations.checking.has.ShopkeeperComparePage ? 'shadow' : null; %>">
        <div class="container-fluid d-flex justify-content-between">
            <div>
                <% if(informations.checking.has.HomePage) { %>
                    <button type="button" class="btn btn-default bg-transparent shadow-none" data-toggle="modal" data-target="#filter"><i class="menu-options-icon text-lilas-1"></i></button>
                <% } else if(informations.checking.has.ShoppingPage) { %>
                    <button onClick="document.location.replace('/home/v1/query?Shop=<%= informations.HTTP.querys.Shop %>&PeriodOf=<%= informations.HTTP.querys.PeriodOf %>&PeriodUntil=<%= informations.HTTP.querys.PeriodUntil %>&PeriodType=<%= informations.HTTP.querys.PeriodType %>&Indicator=<%= informations.HTTP.querys.Indicator %>')" type="button" class="btn btn-lg bg-transparent shadow-none"><i class="back-arrow-icon text-lilas-1"></i></button>
                <% } else if(informations.checking.has.ShopkeeperPage) { %>
                    <button onClick="document.location.replace('/shopping/v1/query?Shop=<%= informations.HTTP.querys.Shop %>&PeriodOf=<%= informations.HTTP.querys.PeriodOf %>&PeriodUntil=<%= informations.HTTP.querys.PeriodUntil %>&PeriodType=<%= informations.HTTP.querys.PeriodType %>&Indicator=<%= informations.HTTP.querys.Indicator %>')" type="button" class="btn btn-lg bg-transparent shadow-none"><i class="back-arrow-icon text-lilas-1"></i></button>
                <% } else if(informations.checking.has.ShopkeeperDetailsPage) { %>
                    <button onClick="document.location.replace('/lojista/v1/query?Shop=<%= informations.HTTP.querys.Shop %>&PeriodOf=<%= informations.HTTP.querys.PeriodOf %>&PeriodUntil=<%= informations.HTTP.querys.PeriodUntil %>&PeriodType=<%= informations.HTTP.querys.PeriodType %>&Indicator=<%= informations.HTTP.querys.Indicator %>')" type="button" class="btn btn-lg bg-transparent shadow-none"><i class="back-arrow-icon text-lilas-1"></i></button>
                <% } else if(informations.checking.has.ShopkeeperComparePage) { %>
                    <button onClick="document.location.replace('/lojistadetalhes/v1/query?Shop=<%= informations.HTTP.querys.Shop %>&PeriodOf=<%= informations.HTTP.querys.PeriodOf %>&PeriodUntil=<%= informations.HTTP.querys.PeriodUntil %>&PeriodType=<%= informations.HTTP.querys.PeriodType %>&Indicator=<%= informations.HTTP.querys.Indicator %>')" type="button" class="btn btn-lg bg-transparent shadow-none"><i class="back-arrow-icon text-lilas-1"></i></button>
                <% } %>

            </div>
            <div class="flex-fill text-center ml-4 pl-sm-2">
                <span class="navbar-brand text-white"><%= informations.page.general.titles.navbar %></span>
            </div>
            <div>
                <% if(informations.checking.has.ShopkeeperDetailsPage) { %>
                    <button onClick="(document.getElementById('BTNSWI').getAttribute('data-indicator') === 'm²') ? document.location.replace('/<%= informations.page.general.type %>/v1/query?Shop=<%= informations.HTTP.querys.Shop %>&Storename=<%= informations.HTTP.querys.Storename %>&PeriodOf=<%= informations.HTTP.querys.PeriodOf %>&PeriodUntil=<%= informations.HTTP.querys.PeriodUntil %>&PeriodType=<%= informations.HTTP.querys.PeriodType %>&Indicator=M2') : document.location.replace('/<%= informations.page.general.type %>/v1/query?Shop=<%= informations.HTTP.querys.Shop %>&Storename=<%= informations.HTTP.querys.Storename %>&PeriodOf=<%= informations.HTTP.querys.PeriodOf %>&PeriodUntil=<%= informations.HTTP.querys.PeriodUntil %>&PeriodType=<%= informations.HTTP.querys.PeriodType %>&Indicator=ABS');" type="button" id="BTNSWI" class="btn btn-sm btn-switch-indicator shadow-none" data-toggle="button" data-indicator="<%= (informations.page.data.API.indicatorType === 'm²') ? 'abs' : 'm²' %>" aria-pressed="false" autocomplete="off">
                        <div id="teste" class="handle-switch-indicator"></div>
                    </button>
                <% } else { %>
                    <button onClick="(document.getElementById('BTNSWI').getAttribute('data-indicator') === 'm²') ? document.location.replace('/<%= informations.page.general.type %>/v1/query?Shop=<%= informations.HTTP.querys.Shop %>&PeriodOf=<%= informations.HTTP.querys.PeriodOf %>&PeriodUntil=<%= informations.HTTP.querys.PeriodUntil %>&PeriodType=<%= informations.HTTP.querys.PeriodType %>&Indicator=M2') : document.location.replace('/<%= informations.page.general.type %>/v1/query?Shop=<%= informations.HTTP.querys.Shop %>&PeriodOf=<%= informations.HTTP.querys.PeriodOf %>&PeriodUntil=<%= informations.HTTP.querys.PeriodUntil %>&PeriodType=<%= informations.HTTP.querys.PeriodType %>&Indicator=ABS');" type="button" id="BTNSWI" class="btn btn-sm btn-switch-indicator shadow-none" data-toggle="button" data-indicator="<%= (informations.page.data.API.indicatorType === 'm²') ? 'abs' : 'm²' %>" aria-pressed="false" autocomplete="off">
                        <div id="teste" class="handle-switch-indicator"></div>
                    </button>
                <% } %>
            </div>
        </div>
    </nav>
</header>

标签: node.jsexpress

解决方案


推荐阅读