Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug report] add extra pages seems to have no effect #1548

Open
yzqdev opened this issue Apr 26, 2024 · 5 comments · May be fixed by #1538
Open

[Bug report] add extra pages seems to have no effect #1548

yzqdev opened this issue Apr 26, 2024 · 5 comments · May be fixed by #1538
Assignees

Comments

@yzqdev
Copy link

yzqdev commented Apr 26, 2024

Description

use extra page or client config to define a route not working

use extra pages

https://v2.vuepress.vuejs.org/advanced/cookbook/adding-extra-pages.html

use plugin api to create a extra page /hello, and it's not found when in dev and production
helloPlugins.ts

import { createPage, type Page, type PluginFunction } from "vuepress/core";
export const helloPlugin =
  (options?:any): PluginFunction =>
  (app) => {
    console.log("hello");
    return {
      name: "hello",
      async onInitialized(app) {
        const helloPage = await createPage(app, {
          path: "/hello",
          frontmatter: { title: "hello" },
        
          content: `\
# 欢迎来到 ${app.options.title}

这是 hello
`,
        });
        app.pages.push(helloPage);
        console.log(app.pages);
      },
    };
  };

register in config.ts

export default defineUserConfig({
  plugins: [
    helloPlugin(),
  
  ],
})

A /hello route is expected, but it is 404 link
reproduction repo repo

use vue-router

https://v2.vuepress.vuejs.org/advanced/cookbook/usage-of-client-config.html
use client config to add a route
this client.ts file

import Hello from './component/Hello.vue';
export default defineClientConfig({
  enhance({ app, router, siteData }) {
    app.component("Hello", Hello);
    router.addRoute({
      path: "/hi",
      name: "hi",
      component: Hello,
    });
  },
})

Hello.vue

<template>
  <div>
<p>hello</p>
  </div>
</template>

<script setup lang="ts">
  
</script>

<style scoped>

</style>

additional info

I see the .vuepress/.temp/pages folder has a hello.html.vue file, it's content is very well ,while in /hello route ,it's not found.

I remembered when vuepress was beta ,the second solution works well.

Reproduction

https://github.com/yzqbugs/vuepress-bugs

Used Package Manager

yarn

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 AMD Ryzen 5 3400G with Radeon Vega Graphics
    Memory: 10.77 GB / 31.95 GB
  Binaries:
    Node: 22.0.0 - ~\AppData\Local\Temp\xfs-9423c53a\node.CMD
    Yarn: 4.1.1 - ~\AppData\Local\Temp\xfs-9423c53a\yarn.CMD
    npm: 10.5.1 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.0.6 - D:\scoop\shims\pnpm.EXE
    bun: 1.1.4 - D:\scoop\shims\bun.EXE
  Utilities:
    Git: 2.43.0.
  Browsers:
    Chrome: Not Found
    Edge: Chromium (123.0.2420.97), ChromiumDev (123.0.2420.10)
  npmPackages:
    @vuepress/bundler-vite: ^2.0.0-rc.9 => 2.0.0-rc.9
    @vuepress/bundler-webpack: Not Found
    @vuepress/cli:  2.0.0-rc.9
    @vuepress/client:  2.0.0-rc.9
    @vuepress/core:  2.0.0-rc.9
    @vuepress/markdown:  2.0.0-rc.9
    @vuepress/shared:  2.0.0-rc.9
    @vuepress/utils:  2.0.0-rc.9
    vue:  3.4.25
    vue-router:  4.3.2
    vuepress: next => 2.0.0-rc.9
@Mister-Hope
Copy link
Member

/hello.html

@yzqdev
Copy link
Author

yzqdev commented Apr 26, 2024

/hello.html

It works for extra page, thank you.

@yzqdev
Copy link
Author

yzqdev commented Apr 26, 2024

common usage (2.0.0-rc.2)

I just downgrade vuepress to 2.0.0-rc.2 the function router.addRoute to add a route works.
while update to 2.0.0-rc3 the added route is not found

repo

client.ts

export default defineClientConfig({
  enhance({ app, router, siteData }) {
    app.component("Hello", Hello);
    router.addRoute({
      path: "/hi",
      name: "hi",
      component: Hello,
    });
  },
});

the router.addRoute added page (vuepress version 2.0.0-rc.2)
https://yzqbugs.github.io/vuepress-bugs/hi

the #1447 custom routes pr seems to break common usage

the reproduction repo (2.0.0-rc3)

https://stackblitz.com/edit/vuepress-ccylja?file=docs%2F.vuepress%2Fclient.ts,docs%2F.vuepress%2FHello.vue,docs%2FREADME.md

click the to hi page button , /hi not found

@Mister-Hope
Copy link
Member

Again, /hi.html, if you need these clean urls, then you must override resolveRoutePath to pervent it being normalized to /hi.html

@Mister-Hope
Copy link
Member

cc @meteorlxy Maybe we should add extra check with a clean URL edition when the original route path not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants