Skip to content

react-custom-projects/react-router-v6

Repository files navigation

This project is an example of using react-router-dom v6, it has the following:

  • Use Routes component.
  • Use Route component.
  • How to set the active class on the active link in NavLink component.
  • Redirect to the correct route after login using location.state.from.pathname
  • How to setup nested routes.
  • Dummy authentication and authorization.
  • Authentication and authorization guards AuthenticationRoute, PrivateRoute, RistrictedRoute.
  • Authorization component RestrictedSection.

Prerequisites:

  • nodeJS > 14.X.X or Docker

Installing / Getting Started:

Development (locally):

  • Clone repo => git clone repo-url
  • cd frontend
  • Install dependencies => yarn install
  • Start the development server => yarn start

Development (using Docker):

  • Clone repo => git clone repo-url
  • cd frontend
  • Install dependencies (required for prettier) => yarn install
  • Start the development server => docker-compose up --build

Update environment variables:

Please keep in mind that environment variables configured using webpack which means that you need to re-run the corresponding environment script (yarn start, yarn run build) if you update the environment file.

Configuring Prettier

This build relies on Prettier formatter to enforce a code style. And ESLint for identifying problematic patterns found in JavaScript code.

  • Setting up prettier:

    1- You can find steps on how to set up prettier formatter with WebStorm/PhpStorm here.

    Notes:

    • It's better to use the local node_modules version of prettier instead of a global one. This is to avoid version conflicts (in case the globally installed version does not match with the versions specified in package.json). So when setting up the file watcher when you follow the steps from the above link you can set program to $ProjectFileDir$\node_modules\.bin\prettier (warning this assumes that node_modules sits in the root of your project. This will need to change if your directory structure changes).
    • You will have to create two file watchers. One for JSX files and one for JS files. The webpack build tools are already configured to work with eslint and prettier. The only thing needed is the two file watchers.

    2- Follow the next steps to set up prettier and eslint on VS Code:

    • Install prettier plugin

    • Install eslint plugin

    • Open VS Code settings CTRL + ,:

      a- Search for formatter => check Format on save

      b- Search for prettier => add .prettierrc in Prettier: Config Path section && check Prettier: Require Config

    3- Please refer to other tutorials if you are using a different IDE.

Available Scripts

In the project directory, you can run:

yarn start

Runs the app in the development mode.
It will open http://localhost:3000 automatically in the browser to see your app.

All changes will be injected automatically without reloading the page.

You will see in the console the following:

  • All redux store related changes
  • Any of the following errors:
    1. Linting errors.
    2. Code format errors (because of prettier)

yarn build

Builds the app for production to the dist folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

yarn build:serve

Serves the app on http://localhost:8080/ from the dist folder to check the production version.

Note: Use this script only if you ran the build script yarn build.

yarn analyze-bundle

It allows you to analyze the bundle size.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published