Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

左上角 logo 和 title 如何添加链接 #69

Closed
flycj opened this issue Jul 26, 2019 · 4 comments · Fixed by #74
Closed

左上角 logo 和 title 如何添加链接 #69

flycj opened this issue Jul 26, 2019 · 4 comments · Fixed by #74

Comments

@flycj
Copy link

flycj commented Jul 26, 2019

image
如上图,如何给红框中的部分添加链接
我使用
image
报错:
image
我该如何做呢?

@LucaLJX
Copy link

LucaLJX commented Jul 27, 2019

左上角的可以通过 logo 传入一个ReactNode进行定制化渲染
楼上需要添加一个连接的需求可以这么实现:

import { Link } from 'react-router'
<ProLayout
      logo={() => (<Link to='/'>
          <img src={require('@/assets/logo.png')} alt='' />
      </Link>)}
</ProLayout>

@flycj
Copy link
Author

flycj commented Jul 27, 2019

image
不行的因为这个组件默认外层就有一个a标签,这个a标签无法修改如上图,无论设置logo 或title 属性为任何 ReactNode 只要有 a 标签就回报下面的错误
image

@LucaLJX
Copy link

LucaLJX commented Jul 27, 2019

image
不行的因为这个组件默认外层就有一个a标签,这个a标签无法修改如上图,无论设置logo 或title 属性为任何 ReactNode 只要有 a 标签就回报下面的错误
image

换了一个写法,这个报错好像是因为ant-d某些组件自带href属性,如果再在里面使用a标签则会报warning,我换了个写法:

import router from 'umi/router'
<ProLayout
      logo={() => (
          <img onClick={() => {
            router.push(`/`)
          }} src={require('@/assets/logo.png')} alt='' />
      )}
</ ProLayout>

@flycj
Copy link
Author

flycj commented Jul 27, 2019


非常感谢,这确实可以解决问题。
那么如果我想把上图中整个红框里面的都加上链接的话, 就需要分别在title 和 logo 属性中写同样的方法。 但是外层那个a 标签缺无法利用上。 希望这个地方可以改善下

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

Successfully merging a pull request may close this issue.

2 participants