Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用相对url向上导航_Jquery_Angularjs_Angular Ui Router - Fatal编程技术网

Jquery 使用相对url向上导航

Jquery 使用相对url向上导航,jquery,angularjs,angular-ui-router,Jquery,Angularjs,Angular Ui Router,因此,我试图向上导航一个级别,但不能完全让它正常工作。下面是一个例子: 当前url: http://localhost/#/tinker/subdir/page1 我希望能够去做这样的事情: $location.url("../page2") http://localhost/#/../page2 在这里结束: http://localhost/#/tinker/subdir/page2 还需要注意的是,我使用的是ui路由器。当我执行$location.url(“../page2”)从

因此,我试图向上导航一个级别,但不能完全让它正常工作。下面是一个例子:

当前url:

http://localhost/#/tinker/subdir/page1
我希望能够去做这样的事情:

$location.url("../page2") 
http://localhost/#/../page2
在这里结束:

http://localhost/#/tinker/subdir/page2
还需要注意的是,我使用的是ui路由器。当我执行
$location.url(“../page2”)从第一页开始,我得到了一个如下所示的url:

$location.url("../page2") 
http://localhost/#/../page2

我相信一定有一个简单的方法来完成我想做的事情。有什么想法吗?

如果您当前的位置是

http://localhost/#/tinker/page1
那么您已经在webroot文件夹中了,因为hashmark(
#
)是一个本地引用。所以当前目录是

http://localhost/
浏览器应该查找名为

/tinker/pages
或者jQuery应该与之配合使用


这只是为了让您了解情况,“#/tinker/page1”不是服务器请求,服务器页面只是“/”

如果您在项目的根目录下启动Web服务器,那么您可以尝试“/subdir/page2”而不是“./page2”,它应该可以工作。最佳做法是从项目根目录而不是“.”给出相对路径,因为这样可以提高可读性

如果您使用的是UI路由器,则不使用URL导航,而是使用状态导航。您可以使用
$state.go('^')

$location.url或$location.href???导航到父状态?我看不到$location有更新的hrefI示例,这是怎么回事?我之所以试图解决这个问题,是因为我可能不知道我想去的确切目录,因为它可能会改变,但我确实知道我想去的相对位置。问题是我的路径可能会根据包含这些“模块”的应用程序而改变。我只知道它们不会相对改变。