Expanding a Landy react app to smoothly transition to a different page with the Router model

I am seeking assistance in updating the Landy out of the box application from https://github.com/Adrinlol/landy-react-template

In a standard React/Javascript model, I would typically write code like the following:

<Route path='/thanks' exact element={<ProtectedRoute><ThankyouPage/></ProtectedRoute>} />
<Route path='/revised' exact element={<ProtectedRoute><ThankyouEditPage/></ProtectedRoute>} />

However, the template is more functionally based and I am unsure how to customize this TypeScript model.

const App = () => (
  <BrowserRouter>
    <I18nextProvider i18n={i18n}>
      <Router />
    </I18nextProvider>
  </BrowserRouter>
);
const Router = () => {
  return (
    <Suspense fallback={null}>
      <Styles />
      <Header />
      <Switch>
        {routes.map((routeItem) => {
          return (
            <Route
              key={routeItem.component} path={routeItem.path} exact={routeItem.exact}
              component={lazy(() => import(`../pages/${routeItem.component}`))}
            />
          );
        })}
      </Switch>
      <Footer />
    </Suspense>
  );
};

My query is regarding adding a new Route and its placement within the code. Any suggestions?

Answer №1

After some brainstorming, I managed to solve the issue by creating a new path /test that is similar to the Home path. I also added a Test folder with an index.tsx file.

const routes = [
  {
    path: ["/", "/home"],
    exact: true,
    component: "Home",
  },
  {
    path: ["/test"],
    exact: true,
    component: "Test",
  },
];

export default routes;

Implemented button action integration:

const testPage = () => {
    history.push("/test");
};

<Button onClick={testPage}>{t("Test")}</Button>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the significance of removing jssStyles in componentDidUpdate or useEffect when incorporating material-ui with NextJS?

After reviewing the material-ui documentation on SSR and examining their sample application here, I made sure to configure my _document.js and _app.tsx files accordingly. Unfortunately, when I attempted to implement componentDidUpdate to remove the jss st ...

React with Typescript - cannot be expressed as a function

I am currently exploring ReactJS and Typescript. While trying to authenticate a user using the methods below, I encountered the following error message: Unhandled Rejection (TypeError): auth.authenticate is not a function onSubmit src/components/Login/ind ...

Template for React Native Boilerplate

As a ReactJS developer, I am currently delving into the world of React Native for an upcoming project. While there is a popular boilerplate widely used in ReactJS development called (along with other options), I have yet to come across something similar f ...

What are the ways to show backend information in a react.js application?

What is the method to display and render data fetched from the backend in react.js? The data retrieved from the backend includes date, time values, and notes. In this scenario, a global variable is used to store the response, which is then assigned to a s ...

The Typescript error message states that the type '{ onClick: () => void; }' cannot be assigned to the type 'IntrinsicAttributes'

I'm a beginner in Typescript and I'm encountering difficulties comprehending why my code isn't functioning properly. My goal is to create a carousel image gallery using React and Typescript. However, I'm facing issues when attempting t ...

The MaterialUI Tooltip gracefully fades out when its display property is set to none

For my ReactJS project, I utilize the MaterialUI ToolTip. However, I am facing an issue where when I change a block's style from display: block to display: none, the tooltip within that block fades away very quickly before disappearing entirely. To s ...

Issue encountered: An error message [ERR_HTTP_HEADERS_SENT] was thrown which indicates that headers cannot be set after they have already been sent to the client while attempting to develop

Recently, I have been working on building a React application and an authorization backend API for an ecommerce project. However, I encountered a problem after updating the username, email, and password in mongoDB. I found that I couldn't log in using ...

Caution: The presence of <tr> inside <form> is not allowed as per validateDOMNesting() function

After I render this form, the browser console displays an error message that says: <tr> cannot appear as a child of <form>. How can I resolve this issue? <form id='works_input_form' onSubmit={handleSubmit}> <tr classN ...

The error message states: "Cannot create element as the React object is not

Recently delving into the world of React and Material UI, I've been working on creating an AppBar with nested Tabs. Here's a snippet of my current approach: import {React, PropTypes, Component} from 'react'; import TodoTextInput from & ...

What is the process for verifying a Bootstrap form?

I have created a form using Bootstrap (Form component in ReactJS), but when I attempt to click on the submit button without entering any input, the form is still submitted. How can I implement form validation so that it only submits when all input fields a ...

Troubleshooting Routing Issues in a Next.js Website Tutorial

After going through the next.js tutorial at https://github.com/zeit/next-learn-demo.git, I encountered an issue starting from stage 3 "dynamic routing". Despite the tutorial indicating that dynamic routing should be working from stages 3 to 8, it wasn&apos ...

What mechanism does the useState() function utilize in React to fetch the appropriate state object and function for a functional component when employing the state hook?

Currently focusing on deepening my understanding of the useState hook in react. I have a question regarding how useState retrieves the state object and modifier function specific to each functional component when it is called. What I'm wondering is w ...

The integration of react-color Saturation with @types/react-color is currently unavailable

In my quest to develop a customized color picker, I am utilizing the react-color library (^2.19.3) together with @types/react-color (^3.0.4). The issue arises when trying to import the Saturation component since it is not exported from the types in the ind ...

Customizing checkboxes in React with JSS: A step-by-step guide

I'm currently working on customizing CSS using JSS as my styling solution, which is proving to be a bit complex while following the w3schools tutorial. https://www.w3schools.com/howto/howto_css_custom_checkbox.asp HTML: <label class="container"& ...

Is there a way to enable intellisense in vscode while editing custom CSS within a material-ui component?

Is there a vscode extension recommendation for intellisense to suggest css-in-js for customized material ui components in .tsx files? For example, I want intellisense to suggest 'backgroundColor' when typing. The closest I found is the 'CSS- ...

What is the reason for me continuously posting an excessive amount of unnecessary data?

As I am relatively new to working with Java and ReactJS, I encountered a major issue while trying to post my data. The problem was that it posted an excessive amount of unwanted data, essentially rendering the entire table. Upon checking my console.log(), ...

Discovering the capabilities of heic2any in a Next.js client-side environment

Here is the code snippet: import convert from 'heic2any' try { convertedImage = await convert({ blob: propsAndFile?.file }) } catch (error) { console.error(error) } Encountered an error while trying to run this code on the client side, ...

The symbol `'.'` is giving a error message of not being recognized as an internal or external command, operable program, or batch file when using React

Attempting to initiate a project from gitlab, I encountered an error when running npm start: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="add9dec880cbdfc2c3d9ed9d839c839d">[email protected]</a> start npm run re ...

Is there a way to restrict my input to only 10 numbers without allowing any characters?

Is there a way to restrict the phone number input to only allow 10 numbers and exclude any other characters? Currently, setting the maxLength attribute limits the characters to 10 but allows additional characters as well. If I change the type attribute to ...

Troubleshooting unit testing issues related to act and useState, Implementing an API request within useEffect

In my React functional component, I am making an API call on the App's onload event. This API call is wrapped in a useEffect hook, and when the data is received, I update the state variable using useState. While trying to write unit tests for this com ...