相对路径和绝对路径
在require.js说明文档里有这么一段话
有时候你想直接饮用一个script,而不是依照(conform)“baseUrl+paths"规则来找它。如果一个模块ID由以下之一的规则,这个ID就不会通过”baseUrl+paths"配置来加载script,而是像普通的script url属性来加载。
- 以.js结束
- 以“/”开始
- url协议(protocol),像 "http:" or "https:".
---------------------------------------------------------
在html中,也经常有绝对路径和相对路径;
- 绝对路径就如url协议开头,像 "http:" or "https:".
- 相对路径都会定义一个baseurl,基本就是在服务器中配置的路径。
- 如在tomcat中配置,baseurl就是conf/server里的docBase
- 如在edp webserver里启动,baseurl就是启动的文件夹(若有另外配置基本路径,则是配置的路径)
- '/xxx'这种的会在baseurl下找对应的xxx文件夹
- '../xxx'这种会在当前目录上的上级目录的子目录中找xxx文件夹
- '../../xxx'这种会在当前目录上的上上级目录的子目录中找xxx文件夹
------------------------------------------------------------------------------
举个例子
web
/index.html
/product/index.html
/case/index.html
/faq/customer/index.html
/business/index.html
/business/index.html
/front/css
/js
其中,baseurl定义为web
- 如果product/index.html里,这样写a标签 <a href="../../case/index.html">
等价于<a href="/case/index.html">;
- 如果product/index.html里,这样写a标签 <a href="../../faq/customer/index.html">
等价于<a href="/customer/index.html">;
- 但如果product/index.html里,这样写a标签 <a href="../../faq/business/index.html">
不等价于<a href="/business/index.html">; 因为web下有两个business文件夹。

浙公网安备 33010602011771号