跳到正文

第一个页面,以及第二个 ​

机器翻译

本页由英文原文机器翻译而来,尚未经过母语审校,欢迎在 GitHub 上提出修改。内容如有出入,以英文原文为准。

任务: 提供两个互相链接的页面。

yaml
# Recipe: two pages, each file of components/ at its own URL.
paths:
  components: ./components

components/ 中的文件就是一个页面,URL 就是它的路径: components/index.q 响应 /,components/about.q 响应 /about。 在包含 quantum.config.yaml 的文件夹中用 quantum start 启动服务器。

xml
<q:component name="Home">
  <!-- components/index.q answers / -->
  <html>
  <head><title>Home</title></head>
  <body>
    <h1>Hello from Quantum</h1>
    <p>This page is components/index.q.</p>
    <a href="/about">About</a>
  </body>
  </html>
</q:component>
xml
<q:component name="About">
  <!-- components/about.q answers /about -->
  <html>
  <head><title>About</title></head>
  <body>
    <h1>About</h1>
    <p>A second page is a second file.</p>
    <a href="/">Home</a>
  </body>
  </html>
</q:component>

没有对应文件的 URL 返回 404:

xml
<q:test name="index.q answers /" page="/">
  <test:visit />
  <test:expect status="200" text="Hello from Quantum" />
</q:test>

<q:test name="about.q answers /about" page="/about">
  <test:visit />
  <test:expect text="A second page is a second file." />
</q:test>

<q:test name="a URL with no file is 404" page="/contact">
  <test:visit />
  <test:expect status="404" />
</q:test>
text
tests/pages.test.q
  PASS  index.q answers /
  PASS  about.q answers /about
  PASS  a URL with no file is 404
3 passed, 0 failed

参见 ROUTE-1。

MIT 许可证 · 使用 VitePress 构建