React-router 4.0 (iii) show navigation based on current URL

Source: Internet
Author: User

Import React, {proptypes} from ' React 'Import Reactdom from' React-dom 'Import {hashrouter, Route, Link, Redirect, withrouter} from' React-router-dom 'Const Home= ({history}) = = {  return(    <div> )}const One= ({history}) = = {  return(    <div> )}const Zlink= ({to,val,isexact}) = = {  return(    <route path={to} exact={isexact} children={({match}) ={Console.log (match,to.tostring ())return(        <div>{Match? ' > ': '}<link to={to}>{val}</link> </div>      )    }}    />//When you need to edit the navigation based on the current URL, you can package a route label outside of link    //The current URL information is obtained through the match of the function parameter under the Children property)}exportdefaultclass App extends React.component {constructor (props) {super (props); } render () {return(      <HashRouter> <div> <ul> <zlink to= "/" val= "Home" isexact={true}/> <zlink to= "/one" val= "first page" isexact={true}/> </ul> <route exact path= "/" component={home}/> <route path= "/one" Compon Ent={one}/> </div> </HashRouter>)}}reactdom.render (<app/>,document.getelementbyid ("App"))

React-router 4.0 (iii) show navigation based on current URL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.