npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-react-router-dom

v1.1.3

Published

Removes the boiler plate code when using react-router-dom

Downloads

177

Readme

vite-react-router-dom

Use this package when you decide to use the react-router-dom and with vite. It simplifies most of the process using nextjs style of routing.

Installation

npm install vite-react-router-dom

and

if you are currently using the react-router-dom remove it and update imports from the react-router-dom to vite-react-router-dom in entire application

npm uninstall react-router-dom

Since Entire context is being will use same context as the one react-router. In the dev and served time it will work but sometimes during the statically served then it might cause the issue.

It exports all exports of the react-router-dom.

Usage

Here we are uplifting most of boiler plate code. By creating the provider and then specifying each individual route manually. You can

import { ViteRoute } from 'vite-react-router-dom'

const App = () => {
  return <React.Fragment>
  <!-- rest of all -->
  <ViteRoute defaultErrorElement={React.Fragment} fallbackElement={<React.Fragment/>} notFoundElement={<React.Fragment/>} routerType="browser"/>
  </React.Fragment>
}

And use it in the place of using the RouteProvider or Routes .....

That is more than enough no need to specify rest of the code. It will pull the routes from application. But you need to follow specific pattern to use it. Which is more similar to how nextjs uses.

Here you need to following rules

  1. File structure

    Under root repo you need to create src folder and under the src folder pages. Under the pages different page routes are accepted. File name has to end with the page.(js/jsx/ts/tsx) or layout.(js/jsx/ts/tsx). File page file immediately after the pages folder will be root pagepath (/)

  2. Page path pattern

    Folder between the pages and page will be route that page. For example you want to create a page with route /hello/good so then your folder pattern has to be ./src/pages/hello/good/page.jsx in the page.jsx your code exists. And component exist in the layout.jsx will act the layout of the file for the With Preceeding Layout act as the parent layout's.

    And if you want any params then you can use the file name wrapping in the curly braces example /user/:userId/ where userId is param. So, it's file has to as follow's ./src/pages/user/{userId}/page.jsx

  3. File pattern

    In react-router-dom we can specify the loader, action along component. So, in the page.jsx, layout.jsx we can specify them export and default one will be the component. It will loaded lazy. So, load of individual page will fast.

    page.jsx / layout.jsx
    
    export default Page // Component or page which will be rendered. 
    
    export const action = async () => {
      // action functionality acts similar to the action props for Route
    }
    
    export const loader = async () => {
      // loader functionality acts similar to the loader props for Route. It can be asynchronous or synchronous
    }

    In the layout component need to <Outlet> component which take in the child of layout from the page just similar to the react-router-dom <Outlet>

Api Reference

This package exports only one component. Which allows following props

defaultErrorElement

Error element which accepts the react type of element.

fallbackElement

Fallback Element been shown during he load of the page. Type is the react element

notFoundElement

If Page is not found then this element will be displayed in the page.

routerType

It accepts browser, hash, memory. Default is browser. can learn about it more from here who they vary

basename

It take base path name that has to be accepted. On top of it will the base will be pathname in the useLocation.

Example

You can see a example over here github pages