2
The first part of the code separates the URL into /
This is the current URL
www.meudominio.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 this category in another object:
var val = split_url[1];
var data = Object.values(livros).filter(function(objecto) {
return objecto.categoria.toLowerCase().indexOf(val) > -1
});
However data
is not getting results back if I set manually val = "ação"
the search finds all related results, but when it is passed through the URL, no results are found.
Obs: This problem only occurs when there are special characters in the URL if I swap the category for something like adventure or romance search finds results, but when there is a special character or uppercase letter in the URL it returns an empty string.
And if you use
encodeURI
in the parameters ?encodeURI('ação')
– Diego Souza