[React] React Router: Querystring Parameters

Define query param in Link, accept path and query :

const Links = () =>
    <nav >
        <Link to={{path: ‘/‘, query: {message: ‘Yo‘}}}>Home</Link>
    </nav>;

Use Query param by props.location.query:

const Container = (props) => <div>{props.location.query.message || ‘Hello‘}<Links /></div>;

-----------------------

import React from ‘react‘;
import {hashHistory, Route, Router, Link, IndexRoute} from ‘react-router‘;

const Container = (props) => <div>{props.location.query.message || ‘Hello‘}<Links /></div>;

const Links = () =>
    <nav >
        <Link to={{path: ‘/‘, query: {message: ‘Yo‘}}}>Home</Link>
    </nav>;

class App extends React.Component {
    render(){
        return(
            <Router history={hashHistory}>
                <Route path="/" component={Container}></Route>
            </Router>
        );
    }
}

export default App;
时间: 2024-11-05 19:00:11

[React] React Router: Querystring Parameters的相关文章

ReactJS React+Redux+Router+antDesign通用高效率开发模板,夜间模式为例

工作比较忙,一直没有时间总结下最近学习的一些东西,为了方便前端开发,我使用React+Redux+Router+antDesign总结了一个通用的模板,这个技术栈在前端开发者中是非常常见的. 总的来说,我这个工程十分便捷,对于初学者来说,可能包含到以下的一些知识点: 一.React-Router的使用 Router是为了方便管理组件的路径,它使用比较简单,一般定义如下就行,需要注意的是,react-router的版本有1.0-3.0,各个版本对应的API大致相似,但也有不同,我使用的是2.X的,

React/React Native 的ES5 ES6写法对照表

转载: http://bbs.reactnative.cn/topic/15/react-react-native-%E7%9A%84es5-es6%E5%86%99%E6%B3%95%E5%AF%B9%E7%85%A7%E8%A1%A8 英文版: https://babeljs.io/blog/2015/06/07/react-on-es6-plus 很多React/React Native的初学者都被ES6的问题迷惑:各路大神都建议我们直接学习ES6的语法(class Foo extends

[React] React Fundamentals: Integrating Components with D3 and AngularJS

Since React is only interested in the V (view) of MVC, it plays well with other toolkits and frameworks. This includes AngularJS and D3. A app with React and D3.js: /** @jsx React.DOM */ var App = React.createClass({ getInitialState: function () { re

[React] React Router: Nested Routes

Since react-router routes are components, creating nested routes is as simple as making one route a child of another in JSX. Make the nested component: class App extends React.Component { render(){ return( <Router history={hashHistory}> <Route pa

[React] React Router: IndexRoute

IndexRoute allows us to define a default child component to be rendered at a specific route when no other sub-route is available. When Home page display, we also make About component as default Route to dsiplay, only when use click Contact link, then

[React] React Router: Router, Route, and Link

In this lesson we'll take our first look at the most common components available to us in react-router; Router, Route, and Link. import React from 'react'; import {hashHistory, Route, Router, Link} from 'react-router'; const Home = () => <div><

[React] React Router: Named Components

In this lesson we'll learn how to render multiple component children from a single route. Define a named component by "components": <Route path="/other" components={ {header: Other, body: OtherBody}}></Route> 'header' and '

[React] React Router: Redirect

The Redirect component in react-router does exactly what it sounds like. It allows us to redirect from from one route to another. import React from 'react'; import {hashHistory, Route, Redirect, Router, Link} from 'react-router'; const Home = () => <

[React] React Router: hashHistory vs browserHistory

In this lesson we'll look at hashHistory which uses a hash hack to track our route changes vs browserHistory which delivers clean urls, but requires server work to implement. Using hashHistory: <Router history={hashHistory}> http://localhost:3333/#/