@putout/plugin-react-router

2.0.1 • Public • Published

@putout/plugin-react-router NPM version

🐊Putout plugin adds ability to migrate to latest version of react router. Not bundled.

Install

npm i putout @putout/plugin-react-router -D

Update .putout.json with:

{
    "plugins": [
        "react-router"
    ]
}

Rules

Here is list of rules:

{
    "rules": {
        "react-router/convert-switch-to-routers": "on",
        "react-router/convert-component-to-element": "on"
    }
}

convert-switch-to-routes

ReactRouter v6 uses Routers instead of Switch. Check out in 🐊Putout Editor.

Example of incorrect code

const {
    Route,
    Switch,
} = require('react-router');

const routes = () => (
    <Switch>
        <Route exact path="/login" component={Login}/>
        <Route exact path="/join" component={Join}/>
    </Switch>
);

Example of correct code

const {
    Route,
    Routes,
} = require('react-router');

const routes = () => (
    <Routes>
        <Route exact path="/login" component={Login}/>
        <Route exact path="/join" component={Join}/>
    </Routes>
);

convert-component-to-element

ReactRouter v6 uses element instead of component. Check out in 🐊Putout Editor.

Example of incorrect code

<Route path="/" component={Home}/>;

Example of correct code

<Route path="/" element={<Home/>}/>;

License

MIT

Package Sidebar

Install

npm i @putout/plugin-react-router

Weekly Downloads

0

Version

2.0.1

License

MIT

Unpacked Size

6.14 kB

Total Files

6

Last publish

Collaborators

  • coderaiser