关于代码中../../hoc/Aux等简写目录路径的技术咨询
Hey there! Relative paths can definitely feel confusing at first, so let’s break down your questions clearly with real-world examples.
1. What does ../../hoc/Aux mean in BurgerBuilder.js?
First, let’s assume a typical React project structure (since BurgerBuilder is a common component from popular React courses):
src/ ├── containers/ │ └── BurgerBuilder/ │ └── BurgerBuilder.js // Your file here ├── hoc/ │ └── Aux.js // The file you're importing └── components/ └── ...
../is standard syntax for "move up one directory level".- So
../../hoc/Auxtranslates to:- Start in the
BurgerBuilder/folder (where your BurgerBuilder.js lives) - First
../takes you up to thecontainers/folder - Second
../takes you up to thesrc/folder - Finally,
/hoc/Auxmoves into thehocfolder and targets theAuxfile
- Start in the
You mentioned "exiting the src folder"—that’s not the case here. We stop at src/ before entering the hoc directory. Also, .../../hoc/Aux is invalid syntax—there’s no such thing as ... in relative paths. Only ../ (up one level) and ./ (current directory) are recognized standard syntax.
2. What does ..**/../**hoc/Aux mean?
The ** is a glob pattern (wildcard) used in tools like Webpack or file system utilities, but it’s not part of standard JavaScript relative path syntax.
In glob terms, ** matches any number of subdirectories. However, ..**/../**hoc/Aux is not a valid or practical path for imports. If you’re trying to skip intermediate folders to reach hoc/Aux, this isn’t the right approach.
Instead, if you want cleaner imports, you can configure your bundler (like Webpack) to treat src/ as a root directory. Then you can write import Aux from 'hoc/Aux' directly, no relative paths needed. For standard relative paths though, ../../hoc/Aux is the correct choice for the structure we outlined.
Recommended Learning Resources
- Node.js Path Module Docs: This covers core JavaScript path handling, including the difference between relative/absolute paths and how
../works under the hood. - Webpack Module Resolution Guide: If you’re using Webpack (common in React projects), this explains how to set up path aliases to simplify imports and avoid messy relative paths.
- ES Modules Import Tutorials: Look for guides on ES module syntax, which break down the rules for specifying paths when importing files.
内容的提问来源于stack exchange,提问作者ARTLoe

