我正在尝试路由javascript中的动态页面
有什么办法可以做到这一点,
localhost/page.html/001
我可以写一个代码,
If (url last characters == 001) {
//Do something
}
<script type="text/javascript">
var lastUrl = window.location;
lastUrl = lastUrl.replace("localhost/page.html/", "");
if(lastUrl == "001"){
alert(lastUrl);
}
</script>
您可以使用:
const currentUrl = window.location.href
要获取侧面的当前URL(在这种情况下为localhost/page.html/001
),然后:
const filterUrl = currentURL.split("/");
if (filterUrl[2] === '001') { /* Do stuff */ } else { /* Do other stuff */ }
如果您的URL总是会像这样,您可以使用此小片段来过滤它们。