Giter VIP home page Giter VIP logo

react-language-router-v6's Introduction

Custom language router (react router dom v6):

  • The main purpose of this project is to create a localized react router.
  • It shows you how to utilize route guards
  • It uses react-i18next package for translation

It has the following route guards:

  • Private route guard => protect the given route based on a token.
  • Public route guard => used for public routes and authentication routes (ex: login, signup, ...etc) {if authenticated it will redirect the user to the home page}
  • Restricted route guard => protect the given route based on a token, and a list of permissions (can be an array or a string).
  • Restricted section => protect the given section based on a list of permissions (can be an array or a string).

It has the following mocks for Jest:

  • MockReduxProvider => for mocking redux provider
  • MockReactIntlProvider => for mocking react-intl provider (if you are using it you need to download it)
  • MockRouter => for mocking react router
  • OverrideRenderOfRTL => overrides the render method of RTL with all providers

Prerequisites:

  • nodeJS > 14.X.X or Docker

Installing / Getting Started:

Development (locally):

  • Clone repo => git clone [email protected]:react-custom-projects/webpack-react-boilerplate.git
  • cd webpack-react-boilerplate
  • Install dependencies => yarn install
  • Start the development server => yarn start

Development (using Docker):

  • Clone repo => git clone [email protected]:react-custom-projects/webpack-react-boilerplate.git
  • cd webpack-react-boilerplate
  • 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 file watchers for TS, TSX and SCSS files. The webpack build tools are already configured to work with eslint and prettier. The only thing needed is the 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.

Site meta tags:

  • This app includes facebook, twitter and regular meta tags

To update them:

  • Open constants.js file and update metaInfo object
  • Open src/assets/images and replace (favicon.png, metaImage.jpg) with your images but using the same name

Extra:

  • Generic error boundary fallback component (you can customize it)
  • Cookies, local storage and sessions storage mangers to store data in the browser. (Note: the data encrypted using crypto-js package before storing it.)
  • Basic mixins (scss/generic/_mixins.scss)
  • Normalize styles (scss/generic/_normalize.scss)
  • App typography styles (scss/generic/_typography.scss)
  • 4 break points (scss/generic/_variables.scss)

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.

yarn test

It runs all test files.

yarn test:watch

  • It runs all unit test files in /src directory using watch mode.
  • Will run all your tests once then again on every change of your source code

yarn test:coverage

It runs test coverage.

yarn test:clear

Clears test cache.

yarn generate component || container || page || hook || service || reducer

  • It creates a boilerplate for component, container, page, custom hook, service or reducer.

react-language-router-v6's People

Contributors

donadam2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.