Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
The code has undergone several enhancements:

Routing Implementation:

Integrated BrowserRouter and Route components from the 'react-router-dom' library to enable multi-page navigation within the application.
Added route definitions using Route components within a Switch, allowing different components to render based on the URL path.
Additional Routes and Components:

Introduced an 'About' page by defining a new functional component called About to display specific content when the '/about' route is accessed.
Created a 'Not Found' component named NotFound to handle 404 errors, rendering a message when a URL doesn't match any defined routes.
Optimized Rendering and Theme Setup:

Utilized the ReactDOM.render method to directly render the ImprovedApp component, simplifying the application setup.
Configured Chakra UI's ChakraProvider with an extended theme that includes color and font settings. Also included a ColorModeScript for improved initial color mode handling for better accessibility.
These changes have transformed the code into a more comprehensive and functional React application with enhanced navigation capabilities, distinct pages for various routes, and an optimized rendering structure with improved theming setup through Chakra UI's functionalities.
  • Loading branch information
rishi457 authored Oct 29, 2023
1 parent d1cc221 commit ae0edfe
Showing 1 changed file with 42 additions and 17 deletions.
59 changes: 42 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,59 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { extendTheme, ChakraProvider, CSSReset, ThemeProvider } from '@chakra-ui/react';
import { BrowserRouter as Router } from 'react-router-dom';
import {
extendTheme,
ChakraProvider,
CSSReset,
ThemeProvider,
ColorModeScript,
} from '@chakra-ui/react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';

const colors = {
brand: {
900: '#1a365d',
800: '#153e75',
700: '#2a69ac',
},
primary: '#3f51b5',
secondary: '#f50057',
};

const fonts = {
body: 'Roboto, sans-serif', // Replace 'Roboto' with your desired font
heading: 'Roboto, sans-serif', // Replace 'Roboto' with your desired font
body: 'Roboto, sans-serif',
heading: 'Roboto, sans-serif',
};

const theme = extendTheme({ colors, fonts });
const theme = extendTheme({ colors, fonts, config: { initialColorMode: 'light' } });

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<ChakraProvider>
<ThemeProvider theme={theme}>
<CSSReset />
<Router>
<App />
</Router>
</ThemeProvider>
function About() {
return (
<div>
<h2>About Page</h2>
<p>This is the about page content.</p>
</div>
);
}

function NotFound() {
return <h2>404 Not Found</h2>;
}

function ImprovedApp() {
return (
<ChakraProvider theme={theme}>
<ColorModeScript initialColorMode={theme.config.initialColorMode} />
<CSSReset />
<Router>
<Switch>
<Route exact path="/" component={App} />
<Route path="/about" component={About} />
<Route component={NotFound} />
</Switch>
</Router>
</ChakraProvider>
</React.StrictMode>
);
);
}

ReactDOM.render(<ImprovedApp />, document.getElementById('root'));

0 comments on commit ae0edfe

Please sign in to comment.