weixin_33691700 2018-05-08 09:05 采纳率: 0%
浏览 96

如何重定向干净的URL

I am trying to redirect from javascript autocomplete search bar element.

Search field works perfectly except one thing. if i was in www.example.com/foo then click a data from search bar. Its redirects me to kinda this pages: the www.example.com/news/1

When i try searchbar again. And click products data from search bar. Its redirect me to the www.example.com/news/products/1

But i want to www.example.com/products/1

"/news" must go away.

if(window.location.pathname.split("/")[1] === "news"){

window.location.hostname.href ="?tab=" +ui.item.category_id+"&id="+ui.item.id;

}
else
window.location.href ="products?tab=" +ui.item.category_id+"&id="+ui.item.id;

window.location.hostname.href

didn't worked for me? How can i use clean link then add like "/products/ui.item.id"

my brief is i can't redirect (href) clean route.

  • 写回答

2条回答 默认 最新

  • weixin_33739541 2018-05-08 09:09
    关注

    You can use document.location.origin for this It will give you base url of page.

      window.location.href = window.document.location.origin + "products?tab=" + ui.item.category_id + "&id=" + ui.item.id;
    
    评论

报告相同问题?