The first part of the code separates the URL into /
This is the current URL
www.mydomain.com/category/action
var url_atual = decodeURI(window.location.href);
var replace_url = url_atual.replace('http://www.meudominio.com/', '');
var split_url = replace_url.split('/');
Now split_url
is an array with two values categoria
and ação
, the function below searches for that category in another object:
var val = split_url[1];
var data = Object.values(livros).filter(function(objecto) {
return objecto.categoria.toLowerCase().indexOf(val) > -1
});
But data
is not returning results, if I manually set val = "ação"
the search finds all related results, but when it is passed through the URL, results are not found.
Note: This problem only occurs when there are special characters in the URL if I change the category to something like adventure or romance results, but when there is any special character or uppercase letter in the URL it returns an empty string.