forked from dunky11/react-saas-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouting.js
More file actions
47 lines (44 loc) · 1.26 KB
/
Routing.js
File metadata and controls
47 lines (44 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React, { memo } from "react";
import PropTypes from "prop-types";
import { Switch } from "react-router-dom";
import PropsRoute from "../../shared/components/PropsRoute";
import Home from "./home/Home";
import Blog from "./blog/Blog";
import BlogPost from "./blog/BlogPost";
import useLocationBlocker from "../../shared/functions/useLocationBlocker";
function Routing(props) {
const { blogPosts, selectBlog, selectHome } = props;
useLocationBlocker();
return (
<Switch>
{blogPosts.map((post) => (
<PropsRoute
path={post.url}
component={BlogPost}
title={post.title}
key={post.title}
src={post.src}
date={post.date}
content={post.content}
otherArticles={blogPosts.filter(
(blogPost) => blogPost.id !== post.id
)}
/>
))}
<PropsRoute
exact
path="/blog"
component={Blog}
selectBlog={selectBlog}
blogPosts={blogPosts}
/>
<PropsRoute path="/" component={Home} selectHome={selectHome} />
</Switch>
);
}
Routing.propTypes = {
blogposts: PropTypes.arrayOf(PropTypes.object),
selectHome: PropTypes.func.isRequired,
selectBlog: PropTypes.func.isRequired,
};
export default memo(Routing);