$location.path(redirecturl)和$location.url(redirecturl)有什么区别?

What is the difference between $location.path(redirecturl) and $location.url(redirecturl)?

本文关键字:redirecturl location 区别 什么 url path      更新时间:2023-09-26

我讨论的是两者的setter方法而不是getter方法

为我$location。Url 并不总是需要一段时间重定向,所以我在考虑使用$location。

区别在于$location.url()$location.path()的getter

url() getter以/path?search=a&b=c#hash的形式返回路径、搜索和哈希,而作为path()只返回/path

在重定向方面,如果它只是指向一个路径,那么是的,我会使用

$location.path(redirectpath).

您可以在$location文档

阅读更多信息

基本上,path只返回路径,但url也返回可能的搜索或其他参数。

查看文档中的示例:

美元location.path :

// given url http://example.com/#/some/path?foo=bar&baz=xoxo
var path = $location.path();
// => "/some/path"

美元location.url :

// given url http://example.com/#/some/path?foo=bar&baz=xoxo
var url = $location.url();
// => "/some/path?foo=bar&baz=xoxo"

path只是url的一部分,不包括searchhash

参见$location docs

中的示例