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] :id? 路由默认跳转失效 #12027

Closed
crazyair opened this issue Jan 4, 2024 · 3 comments
Closed

[Bug] :id? 路由默认跳转失效 #12027

crazyair opened this issue Jan 4, 2024 · 3 comments

Comments

@crazyair
Copy link

crazyair commented Jan 4, 2024

What happens?

使用 :id? 可选参数路由,在 url 输入 http://localhost:8000/m 回车,不会跳转到 m/demo/1 而是跳转到 /app/demo

{
  path: 'demo/:id?',
  name: 'demo2',
  component: './Access',
},

Mini Showcase Repository(REQUIRED)

Please provide a minimal reproduction then upload to your GitHub. 请提供 最小重现,并上传到你的 GitHub 仓库

https://github.com/crazyair/antd5/tree/pathname

How To Reproduce

Steps to reproduce the behavior: 1. 2.

Expected behavior 1. 2.

  1. clone 仓库,使用 pathname 分支
  2. 启用服务,访问 http://localhost:8000/m 并回车

Context

  • Umi Version: latest
  • Node Version: latest
  • Platform: mac
@crazyair
Copy link
Author

crazyair commented Jan 5, 2024

:id? 可选参数不能这样写了?那现在要怎么写

@fz6m
Copy link
Member

fz6m commented Jan 6, 2024

现在 umi 4 没支持可选路由参数,可以写一个空路由代表没匹配的情况:

    {
      path: '/path',
      routes: [
        {
          path: '',
          component: 'path',
        },
        {
          path: ':id',
          component: 'path',
        },
      ],
    }

@fz6m fz6m closed this as completed Jan 6, 2024
@crazyair
Copy link
Author

crazyair commented Jan 7, 2024

主要是不想同一个 component 要写 2 个 route,想尽量精简

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

No branches or pull requests

2 participants