mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 10:41:13 +08:00
fix(react): adding href prop when routerLink is specified (#19481)
This commit is contained in:
@ -17,7 +17,7 @@ interface IonicReactInternalProps<ElementType> extends React.HTMLAttributes<Elem
|
|||||||
|
|
||||||
export const createReactComponent = <PropType, ElementType>(
|
export const createReactComponent = <PropType, ElementType>(
|
||||||
tagName: string,
|
tagName: string,
|
||||||
hrefComponent = false
|
routerLinkComponent = false
|
||||||
) => {
|
) => {
|
||||||
const displayName = dashToPascalCase(tagName);
|
const displayName = dashToPascalCase(tagName);
|
||||||
const ReactComponent = class extends React.Component<IonicReactInternalProps<PropType>> {
|
const ReactComponent = class extends React.Component<IonicReactInternalProps<PropType>> {
|
||||||
@ -41,7 +41,7 @@ export const createReactComponent = <PropType, ElementType>(
|
|||||||
attachEventProps(node, this.props, prevProps);
|
attachEventProps(node, this.props, prevProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleClick = (e: MouseEvent) => {
|
private handleClick = (e: React.MouseEvent<PropType>) => {
|
||||||
const { routerLink, routerDirection } = this.props;
|
const { routerLink, routerDirection } = this.props;
|
||||||
if (routerLink !== undefined) {
|
if (routerLink !== undefined) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -62,16 +62,19 @@ export const createReactComponent = <PropType, ElementType>(
|
|||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
const newProps: any = {
|
const newProps: IonicReactInternalProps<PropType> = {
|
||||||
...propsToPass,
|
...propsToPass,
|
||||||
ref: forwardedRef,
|
ref: forwardedRef,
|
||||||
style
|
style
|
||||||
};
|
};
|
||||||
|
|
||||||
if (hrefComponent) {
|
if (routerLinkComponent) {
|
||||||
|
if (this.props.routerLink && !this.props.href) {
|
||||||
|
newProps.href = this.props.routerLink;
|
||||||
|
}
|
||||||
if (newProps.onClick) {
|
if (newProps.onClick) {
|
||||||
const oldClick = newProps.onClick;
|
const oldClick = newProps.onClick;
|
||||||
newProps.onClick = (e: MouseEvent) => {
|
newProps.onClick = (e: React.MouseEvent<PropType>) => {
|
||||||
oldClick(e);
|
oldClick(e);
|
||||||
if (!e.defaultPrevented) {
|
if (!e.defaultPrevented) {
|
||||||
this.handleClick(e);
|
this.handleClick(e);
|
||||||
|
Reference in New Issue
Block a user