Redirect 如何根据当前URL将当前页面重定向到其他URL?

Redirect 如何根据当前URL将当前页面重定向到其他URL?,redirect,Redirect,我想检查当前url,如果它不是主页,我想使用jQuery或AngularJS将该页面重定向到特定url 请尝试以下代码行: var location = $location.path(); location = location.slice(1, location.indexOf("/")); location = location.toLowerCase(); if (location != 'home

我想检查当前url,如果它不是主页,我想使用jQuery或AngularJS将该页面重定向到特定url 请尝试以下代码行:

       var   location = $location.path();           
        location = location.slice(1, location.indexOf("/"));
        location = location.toLowerCase();


        if (location != 'home') {              
            $location.path('/redirect/somewhere');
        }

为此,您不需要太多jQuery或AngularJS,简单的JS就足够了

location.href也会这样做

例如:


您能添加一些代码来显示您已经尝试过的内容吗?
if(location.href != home_page_URL)
     location.href = new_page_URL;