Main.js 716 B

12345678910111213141516171819202122
  1. import {useRef} from 'react';
  2. import {useRouteNode} from 'react-router5'
  3. import Browser from './Browser';
  4. import ArtistPage from './ArtistPage';
  5. import AlbumPage from './AlbumPage';
  6. export default function Main({dispatch}) {
  7. const scrollRef = useRef(null);
  8. const { route } = useRouteNode('');
  9. let content = <h1>Page not found!</h1>;
  10. if (route.name === 'browser')
  11. content = <Browser dispatch={dispatch} scrollRef={scrollRef} />
  12. else if (route.name === 'artist')
  13. content = <ArtistPage dispatch={dispatch} scrollRef={scrollRef} />
  14. else if (route.name === 'album')
  15. content = <AlbumPage dispatch={dispatch} scrollRef={scrollRef} />
  16. return (
  17. <main ref={scrollRef}>{ content }</main>
  18. )
  19. }