Capítulo 945 de 988

Chapter 945: Files with absolute paths

Core Idea

Why is it not possible to use absolute paths to require assets?

Key Concepts

  • Browsers don't have access to your filesystem
  • Only the public folder is supported by web frameworks
  • Absolute paths are not portable
  • Serving the filesystem via HTTP is dangerous
  • What to do instead
  • Use the public folder
  • Workaround: Use npx serve
  • See also

Code Examples

const MyComp: React.FC = () => {
  return <Img src="C://Users/Joe/Documents/image.png" />;
};
  • What it demonstrates: Usage pattern for Files with absolute paths from the official docs.

Key Takeaways

  1. Understand browsers don't have access to your filesystem when working with Files with absolute paths.
  2. Understand only the public folder is supported by web frameworks when working with Files with absolute paths.
  3. Understand absolute paths are not portable when working with Files with absolute paths.
  4. Understand serving the filesystem via http is dangerous when working with Files with absolute paths.
  5. Understand what to do instead when working with Files with absolute paths.

Connects To

  • 4 0 Alpha: related page in the Miscellaneous (Core) section.
  • ai: related page in the Miscellaneous (Core) section.
  • Animated Emoji: related page in the Miscellaneous (Core) section.