import * as React from 'react'; import { RouteComponentProps } from 'react-router-dom'; import { InteractiveLink } from '../ui/InteractiveLink'; import { P } from '../ui/Paragraph'; import { styled } from '../stitches.config'; const StyledLi = styled('li', { paddingLeft: '18px', textIndent: '-15px', margin: '4px 0', listStyle: 'none', }); interface LiProps { children: React.ReactText; } const Li: React.VFC = ({ children }) => ( {children} ); const LineContainer = styled('div', { margin: '20px 0', }); export const ExampleTwoDeepComponent: React.VFC = ({ location, }) => { const queryPresent = location.search !== ''; const hashPresent = location.hash !== ''; function queryStringTitle() { if (queryPresent) return 'The query string field-value pairs are:'; return 'No query string in the url'; } function hashFragmentTitle() { if (hashPresent) return 'The hash fragment is:'; return 'No hash fragment in the url'; } function linkToShowQueryAndOrHash() { if (queryPresent && hashPresent) return null; const queryString = queryPresent ? location.search : '?field1=foo&field2=bar'; const hashFragment = hashPresent ? location.hash : '#boom!'; let linkText = ''; if (queryPresent && !hashPresent) linkText = 'Show with hash fragment'; if (!queryPresent && hashPresent) linkText = 'Show with query string'; if (!queryPresent && !hashPresent) linkText = 'Show with query string and hash fragment'; return ( {linkText} ); } function parseQueryString() { if (!queryPresent) return []; return location.search .replace('?', '') .split('&') .map((fvPair) => fvPair.split('=')) .map((pair) => [pair[0], pair.slice(1).join('=')]); } return (

This is an example page with query string and hash fragment. Refresh the page or copy/paste the url to test out the redirect functionality (this same page should load after the redirect).

{queryStringTitle()}
    {parseQueryString().map((pair, index) => (
  • {`${pair[0]}: ${pair[1]}`}
  • ))}
{hashFragmentTitle()}
    {hashPresent &&
  • {location.hash.slice(1)}
  • }
{linkToShowQueryAndOrHash()}
); };