kriasoft / kriasoft/react-firebase-starter
Is it possible to route to a single view?
- Dominant language
- JavaScript
- Stars
- 4.5k
- Forks
- 752
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I am getting to grips with React at the moment.
I am using this api in my routes.json file
`http://jsonplaceholder.typicode.com/posts`
This then has its down route to the single view like so:
`http://jsonplaceholder.typicode.com/posts/2`
In my routes.json file I have this:
```
[
{
"path": "/",
"page": "./pages/home",
"chunk": "main",
"data": {
"articles": "GET http://jsonplaceholder.typicode.com/posts"
}
},
{
"path": "/articles/:id",
"page": "./pages/details",
"fetch": {
"task": "GET http://jsonplaceholder.typicode.com/posts/$id"
}
},
{
"path": "/error",
"page": "./pages/error",
"chunk": "main"
},
{
"path": "/about",
"page": "./pages/about"
},
{
"path": "/tasks/:status(pending|completed)?",
"page": "./pages/home"
}
]
```
The home page is rendering the posts and then I can click into the view from the index page. My folder structure is as follows:
pages
details
index.js
styles.css
index.md
In my `pages/details/index.js` I have the following code:
```
import React from 'react';
import Layout from '../../components/Layout';
import s from './styles.css';
import { title, html } from './index.md';
class ArticleDetail extends React.Component {
componentDidMount() {
document.title = title;
}
render() {
return (
{title}
);
}
}
export default ArticleDetail;
```
What i would like to know is can I get the dynamic data from the api endpoint `http://jsonplaceholder.typicode.com/posts/2` into this index.js template view?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with routes.json and pages/details/index.js, then trace how the route's fetch task is made available to the rendered page. Confirm how the /articles/:id parameter maps to the requested post, and consider the work complete when the selected post's data renders in the details view.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100