mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
NamedRedirect is needed after clicking searchform submit
This commit is contained in:
parent
a6090128f4
commit
9661a81b68
2 changed files with 33 additions and 1 deletions
31
src/components/NamedRedirect/NamedRedirect.js
Normal file
31
src/components/NamedRedirect/NamedRedirect.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* This component wraps React-Router's Redirect by providing name-based routing.
|
||||
* This is also special component that gets routes from context.
|
||||
* (Helps to narrow down the scope of possible format changes to routes.)
|
||||
*/
|
||||
import React, { PropTypes } from 'react';
|
||||
import { Redirect } from 'react-router';
|
||||
import { pathByRouteName } from '../../routesConfiguration';
|
||||
|
||||
const NamedRedirect = (props, context) => {
|
||||
const { name, params, query, hash, state, ...rest } = props;
|
||||
const pathname = pathByRouteName(name, context.routes, params);
|
||||
const locationDescriptor = { pathname, query, hash, state };
|
||||
return <Redirect to={locationDescriptor} {...rest} />;
|
||||
};
|
||||
|
||||
const { array, object, string } = PropTypes;
|
||||
|
||||
NamedRedirect.contextTypes = { routes: array };
|
||||
|
||||
NamedRedirect.defaultProps = { hash: '', params: {}, query: {}, state: {} };
|
||||
|
||||
NamedRedirect.propTypes = {
|
||||
hash: string,
|
||||
name: string.isRequired,
|
||||
params: object,
|
||||
query: object,
|
||||
state: object,
|
||||
};
|
||||
|
||||
export default NamedRedirect;
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
import HeroSection from './HeroSection/HeroSection';
|
||||
import NamedLink from './NamedLink/NamedLink';
|
||||
import NamedRedirect from './NamedRedirect/NamedRedirect';
|
||||
import PageLayout from './PageLayout/PageLayout';
|
||||
import RouterProvider from './RouterProvider/RouterProvider';
|
||||
import RoutesProvider from './RoutesProvider/RoutesProvider';
|
||||
|
||||
export { HeroSection, NamedLink, PageLayout, RouterProvider, RoutesProvider };
|
||||
export { HeroSection, NamedLink, NamedRedirect, PageLayout, RouterProvider, RoutesProvider };
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue