[Redux] Navigating with React Router <Link>

Source: Internet
Author: User

We'll learn the address bar using a component from React Router.

In Root.js:

We need to add a param to change the Route:

Import React from 'react'; import {Provider} from 'React-redux'; import {Router, Route, browserhistory} from 'React-router'; import App from './app';ConstRoot = ({store}) = = (    <provider store={store}> <router history={browserhistory}> <route path="/(: Filter) "Component={app}/> </Router> </Provider>) ExportdefaultRoot;

(: Filter) Means:it might not exisits.

In Foot.js, displaying the filter link like this;

ConstFooter = () = (  <p>Show: {" "}    <filterlink filter="Show_all"> All</FilterLink>    {", "}    <filterlink filter="show_active">Active</FilterLink>    {", "}    <filterlink filter="show_completed">completed</FilterLink> </p>);

We want to change it little bit, so it would is more URL friendly:

<p>Show: {" "}    <filterlink filter=" All"> All</FilterLink>    {", "}    <filterlink filter="Active">Active</FilterLink>    {", "}    <filterlink filter="completed">completed</FilterLink> </p>

In the Filterlink.js:

We rewrite the code by using <Link> from ' react-router ':

Import React from 'react'; import {Link} from 'React-router';ConstFilterlink = ({filter, children}) = = (    <Link to={filter = = =' All'?"': Filter} activestyle={{textdecoration:'None', Color:black}} >{Children}</Link>); ExportdefaultFilterlink;

If the filter is ' all ' and then just use the default URL.

If the link is actived and then use the Activestyle.

And we can delete the action creator for Setvisibilityfilter in Actions.js:

// Delete  const Setvisibilityfilter = (Filter) = = ( {    'set_visibility_filter  ',    Filter,});

Aslo Delete the link.js, it is not needed anymore and we use the Link component from React-router.

[Redux] Navigating with React Router <link>

Related Article

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.