SitePage.tsx
import { Component } from "react";
import { Link } from "react-router-dom";
import axios from "axios";
interface Props {
id: any,
site: any,
match: any
}
export class SitePage extends Component<any> {
state = {
site: {},
isLoaded: false
}
componentDidMount() {
axios.get(process.env.REACT_APP_SITES_URL + `/${this.props.match.params.id}`)
.then(res => this.setState({
site: res.data,
isLoaded: true
}))
.catch(err => console.log(err))
}
render() {
const { site, isLoaded } = this.state;
return (
<>
<Link to="/">Go Back</Link>
{/* <h1>{ site[0].title }</h1> */}
</>
)
}
}
export default SitePage
App.tsx
import { lazy, Suspense } from "react";
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import { MessagingProvider } from "../context/messaging/MessagingContext";
import Auth0ProviderWithHistory from '../auth/Auth0ProviderWithHistory';
import Auth0Wrapper from "../auth/Auth0Wrapper";
import ErrorBoundary from "../../utils/components/ErrorBoundary";
import TopBar from "../navigation/TopBar";
import { LoadingBackdrop } from "../../utils/components/Backdrops";
const HomePage = (
lazy(() => (
import(/* webpackChunkName: "HomePage" */"./HomePage"))
)
);
const Sites = (
lazy(() => (
import(/* webpackChunkName: "Sites" */"../sites/main/SitesMain"))
)
);
const SitePage = (
lazy(() => (
import(/* webpackChunkName: "SitePage" */"../sites/main/SitePage"))
)
);
const Projects = (
lazy(() => (
import(/* webpackChunkName: "Projects" */"../projects/main/ProjectsMain"))
)
);
const App = (): JSX.Element => (
<MessagingProvider>
<Router>
<Auth0ProviderWithHistory>
<ErrorBoundary>
<TopBar />
<Suspense fallback={<LoadingBackdrop loading text="Loading Development Hub" />}>
<Auth0Wrapper>
<main className="container">
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/sites" element={<Sites />}></Route>
<Route path="/sites/:id" element={<SitePage />}></Route>
<Route path="/projects" element={<Projects />}></Route>
</Routes>
</main>
</Auth0Wrapper>
</Suspense>
</ErrorBoundary>
</Auth0ProviderWithHistory>
</Router>
</MessagingProvider>
)
export default App;
SiteItem.tsx
import { Component } from 'react'
import { Link } from "react-router-dom";
interface Props {
site: any,
}
export class SiteItem extends Component<Props> {
render() {
const {
id,
title,
deployment_location,
host,
maintenance,
protected_by_cloudflare,
last_updated,
assigned_to
} = this.props.site;
return (
<div className="col-md-4">
<div className="card shadow mb-4">
<div className="card-body">
<h5 className="card-title">
<Link to={`/sites/${ id }`}>{ title }</Link>
</h5>
<div className="card mb-3">
<table className="table table-borderless" style={{ marginBottom: "0px" }}>
<tbody>
<tr className="border-bottom">
<th scope="row">Location</th>
<td>{ deployment_location }</td>
</tr>
<tr className="border-bottom">
<th scope="row">Hosted by us</th>
<td>{ host }</td>
</tr>
<tr className="border-bottom">
<th scope="row">Maintained by us</th>
<td>{ maintenance }</td>
</tr>
<tr className="border-bottom">
<th scope="row">Cloudflare Protected</th>
<td>{ protected_by_cloudflare }</td>
</tr>
</tbody>
</table>
</div>
<div className="card p-2 mb-3">
<div>
<p className="p-0 m-0">
<strong>Last Updated:</strong>
<span className="p-0 m-0"> { last_updated }</span>
</p>
</div>
</div>
<div className="card p-2 mb-3">
<div>
<p className="p-0 m-0">
<strong>Assigned To:</strong>
<span className="p-0 m-0"> { assigned_to }</span>
</p>
</div>
</div>
</div>
</div>
</div>
)
}
}
export default SiteItem
Does anyone know what is causing this issue? I don't think I'm passing something correctly.
I've tried messing with the Props as you can see an Interface, but I ended up just using <any> The route works fine it seems, but it's not getting the id properly. I've also searched many times around on here but couldn't find a solid answer.
Thanks in advance.
