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] vuepress does not support custom routes #100

Closed
Zaba505 opened this issue Apr 6, 2021 · 4 comments
Closed

[bug] vuepress does not support custom routes #100

Zaba505 opened this issue Apr 6, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@Zaba505
Copy link

Zaba505 commented Apr 6, 2021

Bug report

Description

Since Vuepress exposes the Router to clients in clientAppEnhance files, it should be safe to assume that all APIs pertaining to it should be usable, such as, adding routes on-the-fly with Router.addRoute. Vuepress does make this do-able; however, at runtime when trying to navigate to the newly added routes an unexpected error is thrown from Vuepress' custom router resolve guard due to Vuepress not registering the new routes' component as a pagesComponent.

Steps to reproduce

  1. Create a fresh vuepress site plugin/theme.
  2. Add a clientAppEnhance.js with following body:
const Custom = { template: `<div>I'm a custom component for a custom route!</div>` }

export default defineClientAppEnhance(({
  app,
  router,
  siteData
}) => {
  router.addRoute({
    path: '/custom',
    component: Custom
  })
});
  1. Then in Layout.vue, provide a RouterLink:
<RouterLink to="/custom">Custom</RouterLink>

The router reproduction was to confirm that vue-router@v4 does properly support aliases, which is my exact use case. The git repo shows that this issue is triggered regardless if it's an alias or separate path.

Expected behavior

Vuepress shouldn't impede custom navigation.

Screenshots

Alt text

Environment info

  • Browser: Firefox: 87.0
  • Output of vuepress info:
System:
    OS: Linux 5.11 Fedora 33 (Workstation Edition) 33 (Workstation Edition)
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
    Memory: 21.11 GB / 31.22 GB
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.15.1 - /tmp/yarn--1617696568327-0.479712292609096/node
    Yarn: 1.22.10 - /tmp/yarn--1617696568327-0.479712292609096/yarn
    npm: 7.8.0 - ~/.nvm/versions/node/v14.15.1/bin/npm
  Utilities:
    Git: 2.30.2 - /usr/bin/git
  Browsers:
    Chrome: Not Found
    Firefox: 87.0
  npmPackages:
    @vuepress/bundler-vite: Not Found
    @vuepress/bundler-webpack:  2.0.0-beta.6 
    @vuepress/cli:  2.0.0-beta.6 
    @vuepress/client:  2.0.0-beta.6 
    @vuepress/core:  2.0.0-beta.6 
    @vuepress/markdown:  2.0.0-beta.5 
    @vuepress/plugin-active-header-links:  2.0.0-beta.6 
    @vuepress/plugin-back-to-top:  2.0.0-beta.6 
    @vuepress/plugin-container:  2.0.0-beta.6 
    @vuepress/plugin-debug: Not Found
    @vuepress/plugin-docsearch: Not Found
    @vuepress/plugin-git:  2.0.0-beta.6 
    @vuepress/plugin-google-analytics: Not Found
    @vuepress/plugin-medium-zoom:  2.0.0-beta.6 
    @vuepress/plugin-nprogress:  2.0.0-beta.6 
    @vuepress/plugin-palette:  2.0.0-beta.6 
    @vuepress/plugin-pwa: Not Found
    @vuepress/plugin-pwa-popup: Not Found
    @vuepress/plugin-theme-data:  2.0.0-beta.6 
    @vuepress/shared:  2.0.0-beta.4 
    @vuepress/theme-default:  2.0.0-beta.6 
    @vuepress/theme-vue: Not Found
    @vuepress/utils:  2.0.0-beta.5 
    vue:  3.0.11 
    vue-loader:  16.2.0 
    vue-router:  4.0.5 
    vuepress: ^2.0.0-beta.6 => 2.0.0-beta.6 
    vuepress-vite: Not Found
@Zaba505
Copy link
Author

Zaba505 commented Apr 6, 2021

Not entirely sure if this should be considered a bug or feature or both so I went with bug since it's impeding my current work on a custom theme.

I'd also be more than happy to help on a fix for this if it's deemed worth fixing/adding support to Vuepress for custom routes.

@meteorlxy
Copy link
Member

meteorlxy commented Apr 6, 2021

See #69

Of course we can avoid this error, but if you add routes dynamically, the page is not possible to be pre-rendered during build. So it is not a recommended usage.

We'll add some examples in documentation for theme development

@meteorlxy meteorlxy added the documentation Improvements or additions to documentation label Apr 6, 2021
@meteorlxy
Copy link
Member

meteorlxy commented Apr 6, 2021

After some investigation, I find this is kind of a "bug" and can be fixed 🤔

But adding dynamic routes is still not recommended, unless you know what's the drawback.

@meteorlxy meteorlxy added bug Something isn't working and removed documentation Improvements or additions to documentation labels Apr 6, 2021
@Zaba505
Copy link
Author

Zaba505 commented Apr 6, 2021

@meteorlxy Thanks for looking into this! That other issue is also really useful.

We'll add some examples in documentation for theme development

But adding dynamic routes is still not recommended, unless you know what's the drawback.

I also think adding some examples about dynamic pages to the documentation would be a great idea to help guide others away from dynamic routes or at least advice them that there is most likely a better solution for what they may be trying to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants