【发布时间】:2019-08-09 08:08:37
【问题描述】:
我正在尝试使用 JS 附加到现有的 Laravel 路由,而无需构建 URL 对象。
我的路线在下面的 HTML 元素中。
<div class="clickable-element js-location-id" data-href="{{ route('report.file.list')}}">DATA</div>
这是我构建新 URL 的 JS 函数。目前,新的 URL 是硬编码的,但我更喜欢从 html 元素中获取现有路由并将 id 附加到它,所以如果我更新路由,我不需要更新 JS。
buildTileFilter(){
//Can I grab the route from the html element without having to create a url?
let url = new URL('http://sample_site/report/file/list?f%5B%5D');
let query_string = url.search;
let search_params = new URLSearchParams(query_string);
search_params.set('f[]', this.locationId);
url.search = search_params.toString();
let new_url = url.toString();
return new_url;
}
【问题讨论】:
标签: javascript laravel url routes