GithubHelp home page GithubHelp logo

gxlmyacc / react-view-router Goto Github PK

View Code? Open in Web Editor NEW
24.0 24.0 3.0 4.84 MB

write route config like vue-router in react

License: MIT License

JavaScript 19.85% CSS 1.50% TypeScript 77.72% HTML 0.92%
react react-router react-router-dom route-config router vue-router

react-view-router's People

Contributors

dependabot[bot] avatar gxlmyacc avatar

Stargazers

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

Watchers

 avatar

react-view-router's Issues

懒加载报错

// / routes.js
import { normalizeRoutes, lazyImport } from 'react-view-router';
import Home from '@/layout';

const routes = normalizeRoutes([
  {
    path: '/home',
    component: Home,
    children: [
      { path: '/', redirect: 'main' },
      {
        path: 'main',
        // 懒加载
        component: lazyImport(() => import('@/view/pulmonary')),
      },
    ],
  },
  // {
  //   path: '/login',
  //   component: Login
  // }
]);

export default routes;

首先ts提示类型不正确

不能将类型“RouteLazy”分配给类型“ComponentType<{}> | undefined”。
  不能将类型“RouteLazy”分配给类型“FunctionComponent<{}>”。
    类型“RouteLazy”提供的内容与签名“(props: { children?: ReactNode; }, context?: any): ReactElement<any, any> | null”不匹配。

改造成下面形式

     components: {
          default: lazyImport(() => import('@/view/pulmonary')),
        },

浏览器抛出error

React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object

前缀不支持''

给path设置为''会自动转化为/

Cannot read properties of undefined (reading 'default')

Hello @gxlmyacc , I am trying to use this awesome routing tool, however, I am getting this error in the browser console:

Uncaught TypeError: Cannot read properties of undefined (reading 'default')
    at Module.get [as RouterView] (Middleware.js:101)
    at getExportByName (modules.js?hash=2d5fd69c588994d60e8131b827f3ffc3ec129d1f:1001)
    at modules.js?hash=2d5fd69c588994d60e8131b827f3ffc3ec129d1f:962
    at Array.forEach (<anonymous>)
    at forEachSetter (modules.js?hash=2d5fd69c588994d60e8131b827f3ffc3ec129d1f:945)
    at Entry.Ep.runSetters (modules.js?hash=2d5fd69c588994d60e8131b827f3ffc3ec129d1f:809)
    at Module.runSetters (modules.js?hash=2d5fd69c588994d60e8131b827f3ffc3ec129d1f:377)
    at fileEvaluate (modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:404)
    at Module.require (modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:270)
    at require (modules-runtime-hot.js?hash=d12281259a6cee99786429a66f76b05f13449c7f:310)

Any idea to solve it?

I am using:

  • Meteor JS 2.4
  • Node 14.17
  • Mac 11.2

How to inject transitions?

Hi @gxlmyacc , I am trying to use this plugin with react-view-router to inject transitions when a route is changed. The plugin is inspired by the vue transition modes and it was designed to work with React Router, so, I guess that it could work as well with react-view-router since this router is based on React Router. An example with React Router is the following code:

<Route key={path} exact path={path}>
              {({ match }) => (
                <CSSTransition
                  in={match != null}
                  timeout={300}
                  classNames="page"
                  unmountOnExit
                >
                  <div className="page">
                    <Component />
                  </div>
                </CSSTransition>
              )}
            </Route>

So, with react-view-router I have this code:

<CSSTransition in={false} // "in" prop should have a condition as value.
timeout={300} classNames="sectionView" unmountOnExit>
                            <div className="sectionView">
                                <RouterView name="sectionView" />
                            </div>
                        </CSSTransition>

So, I'm still figuring out where to take the match variable to inject the condition match !== null.

You can see the full example with React Router here.

Is there a way to achieve it?

How to have a nested route with a root path?

Hello, I started to implement this routing tool in a react app, so, I am trying to replicate the routing configuration from another Vue app that I have made, however, I am having an issue with nested routes. To make this more understandable, this is my routing configuration:

routes.ts

import { normalizeRoutes } from 'react-view-router';
import LayoutSPA from '/imports/ui/layouts/LayoutSPA';
import LayoutAuth from '/imports/ui/layouts/LayoutAuth';
import Login from '/imports/ui/views/Auth/Login';
import ForgotPassword from '/imports/ui/views/Auth/ForgotPassword';

export default normalizeRoutes([
	{ path: '/', index: 'home' },
	{
		path: '/home',
		name: 'home',
		component: LayoutSPA
	},
	{
		path: '/login',
		component: LayoutAuth,
		children: [
			{
				name: 'forgotPassword',
				path: '/forgot-password',
				components: {
					sectionView: ForgotPassword
				}
			},
			{
				name: 'login',
				path: '',
				components: {
					sectionView: Login
				}
			}
		]
	}
]);

In Vue 2 apps, I can use nested views with root paths, however, in the React app, if I want to access to ForgotPassword view, I have to put the /login/forgot-password path, whereas in Vue you can put only /forgot-password and it will work because the pathname for ForgotPassword view starts with a slash ( / ). So, I was wondering if this can be possible somehow?

On the other hand, I have 2 questions more:

What is the difference between index and redirect fields of a route?
What is the name property used for? (I use it in Vue apps to identify the route and it was used to navigate between routes, as an alternative field from the path field)

Hope you can help me with this :) .

next

Do you plan ssr support (next.js)?

`global` is not defined

After installing and running, the console throws an error

Uncaught ReferenceError: global is not defined
    <anonymous> global.ts:5

It looks like global.ts references global and it is not defined. Maybe you meant to use globalThis?
Thanks

Errors in package

Could not find dependency: 'core-js' relative to '/node_modules/react-view-router/esm/index.js'

after build scripts go to esm folder, but code in es folder

SSR React

Hi, thanks for router like vuejs, its good router API

how to use with SSR?

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.