better react-router-dom idiom (#50)

This commit is contained in:
Michael Quigley 2022-09-19 15:37:49 -04:00
parent 539ffe78b5
commit 3a45ced9e1
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 24 additions and 17 deletions

View File

@ -4,8 +4,10 @@ import Network from './Network';
import Token from './Token';
import Version from './Version';
import { useEffect, useState } from 'react';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import Register from "./Register";
const App = () => {
const Overview = () => {
const [user, setUser] = useState();
useEffect(() => {
@ -52,5 +54,16 @@ const App = () => {
);
}
const App = () => {
return (
<Router>
<Routes>
<Route path={"/"} element={<Overview />}/>
<Route path={"register/:token"} element={<Register />} />
</Routes>
</Router>
);
}
export default App;

View File

@ -1,6 +1,13 @@
import { useParams } from 'react-router-dom';
const Register = () => {
const { token } = useParams();
return (
<h1>Register!</h1>
<div>
<h1>Register!</h1>
<p>token = "{token}"</p>
</div>
)
}

View File

@ -1,26 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import Register from "./Register";
import * as gateway from "./api/gateway";
import {createBrowserRouter, RouterProvider} from "react-router-dom";
const router = createBrowserRouter([
{
path: "/",
element: <App />,
},
{
path: "/register",
element: <Register />,
}
]);
import App from "./App";
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<RouterProvider router={router} />
<App />
</React.StrictMode>
);