Sigma-Labs-XYZ / Explain-AI

An AI-powered source of all human knowledge
https://explainai.me/
1 stars 1 forks source link

React Router #16

Open DomVinyard opened 1 year ago

DomVinyard commented 1 year ago

We need to implement React Router in our React application to allow for navigation between different pages. We want to create two initial routes:

Tasks:

const Homepage = () => {
  return (<div>
    <h1>Homepage</h1>
    <a href="/javascript">Javascript</a>
  </div>)
}

Acceptance Criteria:

DomVinyard commented 1 year ago

This is a useful resource for learning about React Router: https://www.youtube.com/watch?v=Ul3y1LXxzdU

swdilip commented 1 year ago

Should clicking the <a> tag on the homepage take the user to the Topic Page? and is the Topic Card to be rendered within topic page?

mdapim commented 1 year ago

Whats the purpose of the colon before topic please e.g. "/:topic"

bp289 commented 1 year ago

After implementing the AppRouter.js, should we delete the App.js ? we have chosen to have the AppRouter file in the index.js file where the App.js would usually go:

import AppRouter from "./AppRouter";

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <React.StrictMode>
    <AppRouter />
  </React.StrictMode>
);

reportWebVitals();
Ademsk1 commented 1 year ago

@bp289 We've deleted it, but I'm sure it's no harm @mdapim This allows us to use the useParams() feature of react-router-dom. Remember in Flask we were able to use @app.route('/home/<id>') ? Where ID was a variable we could set? Well, the colon acts just like the <>. We can interact with it using useParams() e.g. const {id} = useParams() inside the element

Ademsk1 commented 1 year ago

Will there be actually 3 different routes, i.e.

"/" : HomePage
"/topic/" : Main topics page
"topic/:topic" : Particular Topic of Interest Page

I'd argue it should be like this to allow navigation between the home and topics page to be more streamlined for the user. If I was on a particular topic, then navigated to home, and then back to topic, I wouldn't want to see the last topic I saw using the navigation, but instead perhaps a list of recently added topics.

mdapim commented 1 year ago

@Ademsk1 I thought that as well so didn't know whether to get rid of initial app.js file as that could be the topics page before particular topic of interest

DomVinyard commented 1 year ago

Will there be actually 3 different routes, i.e.

It would be a good idea for a website with multiple features, but in this case let's keep the URL super simple like:

https://url.com/javascript https://url.com/react

mdapim commented 1 year ago

@DomVinyard When using useParams() should we be taking into account invalid requests such as below yet, or would that be a separate ticket please?

Image