ant-design / ant-design-pro

👨🏻‍💻👩🏻‍💻 Use Ant Design like a Pro!
https://pro.ant.design
MIT License
36.47k stars 8.14k forks source link

Duplicated menus for root url / #9441

Closed Mayazure closed 2 years ago

Mayazure commented 2 years ago

I'm trying to build a site where the root url (i.e. '/') directs to a standalone home page rather than a layout with nested routes. Here I have a very simple route config:

// routes.ts
export default [
  {
    path: '/',
    name: 'home',
    icon: 'smile',
    component: './Home',
  },
  {
    path: '/welcome',
    name: 'welcome',
    icon: 'smile',
    component: './Welcome',
  },
  {
    component: './404',
  },
];

And my pages folder:

image

The above routes give me the following menu render:

root1

It works except that there are two 'Home' menus rendered on the header, the second of which is selected by default when entering the site.

The first 'Home' menu directs to '/index.html', which is a strange url. I don't even understand where does this 'indx.html' come from.

root2

Am I missing something here? What is the correct way to config path and component for root url?

github-actions[bot] commented 2 years ago

Hello @Mayazure. Please provide a online reproduction by forking this link https://codesandbox.io/ or a minimal GitHub repository.

你好 @Mayazure, 我们需要你提供一个在线的重现实例以便于我们帮你排查问题。你可以通过点击 此处 创建一个 codesandbox 或者提供一个最小化的 GitHub 仓库。

Mayazure commented 2 years ago

@chenshuai2144 Thanks. Please check this repo: https://github.com/Mayazure/demo-antdpro-rooturl

chenshuai2144 commented 2 years ago

you can close exportStatic or set Router.exact = false。

 {
    path: '/',
    exact: false,
    name: 'home',
    icon: 'smile',
    component: './Home',
  }, 
Mayazure commented 2 years ago

you can close exportStatic or set Router.exact = false。

 {
    path: '/',
    exact: false,
    name: 'home',
    icon: 'smile',
    component: './Home',
  }, 

@chenshuai2144 That does not solve the problem. With the root path's exact match set to false, all other path will be directed to the root component. Following is my routes and now both '/' and '/welcome' will be directed to './Home'. What I need is '/' directs to './Home' while '/welcome' directs to './Welcome'

// routes.ts
export default [
  {
    path: '/',
    exact: false,
    name: 'home',
    icon: 'smile',
    component: './Home',
  },
  {
    path: '/welcome',
    name: 'welcome',
    icon: 'smile',
    component: './Welcome',
  },
  {
    component: './404',
  },
];
chenshuai2144 commented 2 years ago
{
    path: '/',
    exact: false,
    name: 'home',
    icon: 'smile',
    component: './Home',
  },

放到最后