4.0.0-alpha.3 • Published 4 years ago

@redux-model/web-router v4.0.0-alpha.3

Weekly downloads
26
License
MIT
Repository
github
Last release
4 years ago

@redux-model/web-router

A redux router model based on @redux-model/react that support react and vue, it works in browser.

Installation

npm install @redux-model/web-router

Register

Register Browser history

import { BrowserRouterModel } from '@redux-model/web-router';

export routerModel = BrowserRouterModel.init();

Register Hash history

import { HashRouterModel } from '@redux-model/web-router';

export routerModel = HashRouterModel.init();

Methods

push, replace, go, goBack, goForward

routerModel.push('/user');
routerModel.goBack();

Listeners

class TestModel extends Model<Data> {
    constructor() {
        super();

        routerModel.listenPath('/user/:id', ({ id }, location, action) => {
           console.log(id);
        });

        routerModel.listenAll((localtion, action) => {
            // All history changes will be handle here
            // Do something...
        });

        const token = routerModel.listenPath('/article/:id/category/:cate', ({ id, cate }, location, action) => {
            console.log(id);
            console.log(cate);
        });

        // In some case, you don't want to listen it any more.
        routerModel.unlisten(token);
    }
}

export const testModel = new TestModel();

Data

In Hooks

import { routerModel } from '@redux-model/web-router';

const App = () => {
  const { location, action } = routerModel.useData();

  return <div />;
};

In Class Component

import { routerModel } from '@redux-model/web-router';

type Props = ReturnType<typeof mapStateToProps>;

class App extends Component<Props> {
  render() {
    return <div />;
  }
}

const mapStateToProps = () => {
  return {
    location: routerModel.data.location,
    action: routerModel.data.action,
  };
};

export default connect(mapStateToProps)(App);
4.0.0-alpha.3

4 years ago

4.0.0-alpha.2

4 years ago

4.0.0-alpha.1

4 years ago

4.0.0-alpha.0

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.2

4 years ago

2.0.0-rc.0

4 years ago

2.0.0-rc.1

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.3

4 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.1-rc.0

5 years ago

1.2.0

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.1.0-rc.0

5 years ago

1.0.0

5 years ago