【问题标题】:./ vs directory name in paths and file linking./ vs 路径和文件链接中的目录名
【发布时间】:2021-07-18 18:28:00
【问题描述】:

在使用路径时使用 ./ 和直接写目录或文件名有什么区别。

假设我有以下简单的结构:

project
│   index.html  
│
└───pages
│   │   file1.html
│   │   file2.html
│   │
│   └───about
│       │   file3.html
│       │   file4.html

如果我说在file1.html 写链接有什么区别是下面的方式?

<a href="./about/file3.html">Link</a>

对比

<a href="about/file3.html">Link</a>

重要

我知道./ 是什么意思! 我只是想知道是否有实际的区别和优势/劣势

【问题讨论】:

    标签: javascript php html directory


    【解决方案1】:

    据我所知,在网络上,两者在功能上是等效的。

    但是,在 Node.js 应用程序中./ 将本地文件与库文件(即来自 NPM/node_modules 的文件)区分开来。

    换句话说:

    import Foo from 'foo';
    

    从名为“foo”的库中导入Foo 变量node_modules,同时:

    import Foo from './foo'
    

    将改为从同一目录中名为 foo.js 的文件中导入 Foo

    【讨论】:

      猜你喜欢
      • 2014-10-20
      • 1970-01-01
      • 2011-02-01
      • 2012-10-04
      • 1970-01-01
      • 2014-04-21
      • 1970-01-01
      • 1970-01-01
      • 2019-11-11
      相关资源
      最近更新 更多