[英]How do I create a hyperlink to my nav bar with React?
import React, { Component } from 'react';
class About extends Component {
render() {
return(
<div><h1>About Page</h1></div>
)
}
}
export default About;
I have been stuck for an hour trying to figure out how to create a hyperlink similar to href but with react. 我被困了一个小时,试图弄清楚如何创建类似于href的超链接,但有反应。 This is a new .js file and I want to create an external link to it so when I click the Nav Bar , instead of it directing me to blank page, it can direct me to my Twitter or something else.
这是一个新的.js文件,我想创建一个指向该文件的外部链接,因此当我单击导航栏时,它可以将我定向到Twitter或其他内容,而不是将我定向到空白页。 Thanks!
谢谢!
You could do like this 你可以这样
import React from 'react';
import { Link } from 'react-router';
class About extends React.Component {
render() {
return (
<div>
<p>Click here to know about us.</p>
<ul>
<li><Link to="/about">About Us</Link></li>
</ul>
</div>
);
}
}
export default About;
you can use react-router for it. 您可以使用react-router。 https://reacttraining.com/react-router/web/example/custom-link it has a link element when you wrap in router you should be able to change the route.. hope it helps
https://reacttraining.com/react-router/web/example/custom-link当您包装路由器时,它具有链接元素,您应该能够更改路线。希望对您有所帮助
Try this 尝试这个
import React, { Component } from 'react';
import { Link } from 'react-router';
class About extends Component {
render() {
return(
<div><h1>About Page</h1>
<Link to="url" activeClassName="active">"Link Name"</Link>
</div>
);
}
}
export default About;
Link is a component of react-router-dom not react-router
. 链接是react-router-dom的组件,而不是
react-router
。 Try changing your import as follows: 尝试如下更改导入:
import React from 'react';
import { Link } from 'react-router-dom';
class About extends React.Component {
render() {
return (
<div>
<p>Click here to know about us.</p>
<ul>
<li><Link to="/about">About Us</Link></li>
</ul>
</div>
);
}
}
export default About;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.