node.js - 在 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>
解决方案
推荐阅读
- javascript - 如何在html的输入字段中突出显示新文本
- c - 试图在 C 中捕获 SIGSEGV 信号
- python - 我正在尝试使用 for 循环创建 3D 矩阵
- r - 如何在 R 中取消嵌套数据框列表的列表?
- c - 如何在两个不同的程序之间分离两个scanfs?
- c++ - C++ 中字符串的 32 位 LFSR 加密
- node.js - 如何使用 axios (Vue.js) 将我的参数 req.body 填充到我的 Express.js 服务器
- amazon-web-services - 如何通过 Terraform 描述 API Gateway 资源?
- azure-service-fabric - 服务结构复制器卡住
- numerical-methods - 如何以数值稳定的方式计算 (exp(t) - 1)/t?