1.0.0-alpha.28 • Published 1 month ago

@concepta/react-router v1.0.0-alpha.28

Weekly downloads
-
License
BSD-3-Clause
Repository
-
Last release
1 month ago

@rockets-react/react-router

Rockets Router package to handle app routeing system

IMPORTANT

When building your Routing system, you need to remember these!

This module only helps you to handle routing on your application. There is no magic, you are still responsible for maitaing the state of your app and navigate between the routes manually.

Here is how it works

This package will expose the following

  • A Router component to wrapp all your app privates and publics routes
  • Methods to make the routes navigation

!!! Important !!!

  • You have to provide a isAuth boolean property, NotFound and Unauthorized components to Router component, so the Router will have a component to render when these situations happens.

Examples

These are very rough examples. We intend to improve them ASAP.

Simple User Login

import {
  ProtectedRoute,
  PublicRoute,
  Router,
  useNavigate,
} from '@concepta/react-router';

const NotFound = () => {
  return <div>Not Found</div>;
};

const Unauthorized = () => {
  return <div>Unauthorized</div>;
};

const Home = () => {
  return <div>LOGGED IN!</div>;
};

const LoginForm = () => {
  const { doLogin, user } = useAuth();
  const navigateTo = useNavigate();

  React.useEffect(() => {
    if (user) {
      navigateTo('/', { replace: true });
    }
  }, [user]);

  const onClickSignIn = async (user: string, password: string) => {
    doLogin({ email: user, password });
  };

  return <SimpleLoginForm onClickSignIn={onClickSignIn} />;
};

const AppWrapper: React.FC = () => {
  const { user } = useAuth();

  return (
    <Router
      isAuth={!!user}
      NotFoundComponent={NotFound}
      UnauthorizedComponent={Unauthorized}
    >
      <ProtectedRoute path="/" Component={Home} />
      <PublicRoute path="/login" Component={LoginForm} />
    </Router>
  );
};
1.0.0-alpha.28

1 month ago

1.0.0-alpha.27

1 month ago

1.0.0-alpha.26

3 months ago

1.0.0-alpha.25

3 months ago

1.0.0-alpha.24

3 months ago

1.0.0-alpha.23

4 months ago

1.0.0-alpha.22

4 months ago

1.0.0-alpha.21

4 months ago

1.0.0-alpha.20

5 months ago

1.0.0-alpha.19

5 months ago

1.0.0-alpha.18

5 months ago

1.0.0-alpha.17

5 months ago

1.0.0-alpha.16

5 months ago

1.0.0-alpha.12.1

6 months ago

1.0.0-alpha.8

7 months ago

1.0.0-alpha.7

8 months ago

1.0.0-alpha.6

8 months ago

1.0.0-alpha.10

7 months ago

1.0.0-alpha.15

6 months ago

1.0.0-alpha.12

6 months ago

1.0.0-alpha.11

6 months ago

1.0.0-alpha.14

6 months ago

1.0.0-alpha.13

6 months ago

1.0.0-alpha.5

1 year ago

1.0.0-alpha.3

1 year ago

1.0.0-alpha.2

1 year ago

1.0.0-alpha.1

2 years ago