Git Product home page Git Product logo

render's People

Contributors

oedotme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

render's Issues

Guarding private dynamic routes

Love this library, great work! One thing though that I am not sure how to do is add a slug path to the PRIVATE paths array.

Example say location.pathName = '/order/1043', currently the PRIVATE paths matches on exact ones. Would be cool to specify:

// Slug path
const PRIVATE = ['/logout', '/order/:orderId']

// Wildcard path
const PRIVATE = ['/logout', '/order/*']

Here is the modified guard.tsx, this might be a great example to add the the project?

import { Navigate, useLocation } from 'react-router-dom'

import { useAuth } from '@/context'

const PRIVATE = ['/logout', '/order/:orderId']
// or this
// const PRIVATE = ['/logout', '/order/*']
const PUBLIC = ['/login']

const findMatchingPath = (currentPath: string, pathPatterns: string[]) => {
  const currentPathParts = currentPath.split('/')

  for (const pattern of pathPatterns) {
    const patternParts = pattern.split('/')

    if (currentPathParts.length !== patternParts.length && !pattern.endsWith('*')) {
      continue
    }

    let isMatch = true
    for (let i = 0; i < patternParts.length; i++) {
      if (patternParts[i] === '*' || patternParts[i].startsWith(':')) {
        continue
      }
      if (currentPathParts[i] !== patternParts[i]) {
        isMatch = false
        break
      }
    }

    if (isMatch) {
      return pattern
    }
  }

  return null
}

export const Guard = ({ children }: { children: JSX.Element }) => {
  const auth = useAuth()
  const location = useLocation()

  const authedOnPublicPath = auth.token && findMatchingPath(location.pathname, PUBLIC)
  const unAuthedOnPrivatePath = !auth.token && findMatchingPath(location.pathname, PRIVATE)

  if (authedOnPublicPath) return <Navigate to="/" replace />
  if (unAuthedOnPrivatePath) return <Navigate to="/login" replace />

  return <>{children}</>
}

Why You still recommended NextJs?

Why You still recommended NextJs after you can create something like it? Or why you not create for example: refine.dev?

But, Many applications no need SSR.. no need SEO.. Many application want stay work at offline network.. and SSR Next cannot do that.. Client side react can do.. and simple deployment

Nice to see your library.. good job..

[Req] Add unit/e2e test with MSW

Dear @oedotme,

really appreciate your works, whether it is possible to add vitest (MSW) and cypress to this template? it'd be helpful to replace CRA template with this.

thanks

Nested layout

Hi, thanks for your work! I think it'll nice for supporting nested layout

Expected

similar behaviour with basic example react-location

- Posts (has a list of posts with outlet)
|-- PostIndex
|-- DetailPost :id

when navigating from index to detail post, only re-render the outlet

Use react router 6

Hi @oedotme really appreciate your work. It's so clean and useful.

Just one request. Since some apisare charged on React Router 6 compare to version that you used in your tutorial, I think it's so useful if you can update this repo and your tutorial to the latest vversion of React Router.

Again thanks for your work.

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.