Git Product home page Git Product logo

react-mobile's Introduction

yarn add

yarn start

yarn build

脚手架搭建

npx create-react-app my-app

安装 less

yarn add --dev less less-loader

根路径下新增 config-overrides.js 修改默认配置

const {
  override,
  addLessLoader
} = require('customize-cra');

module.exports = override(
  addLessLoader(),
);

安装 antd-mobile

yarn add antd-mobile

使用按需加载

yarn add babel-plugin-import --dev

按需加载修改 config-overrides.js

const {
  override,
  addLessLoader,
  fixBabelImports,
} = require('customize-cra');

module.exports = override(
  addLessLoader(),
  fixBabelImports('import', {
    libraryName: 'antd-mobile',
    style: 'css',
  })
);

安装 router

yarn add react-router-dom

config-overrides.js 添加别名配置

const path = require('path');
const {
  override,
  addLessLoader,
  fixBabelImports,
  addWebpackAlias,
} = require('customize-cra');

module.exports = override(
  addLessLoader(),
  fixBabelImports('import', {
    libraryName: 'antd-mobile',
    style: 'css',
  }),
  //   引入别名
  addWebpackAlias({
    '@': path.resolve(__dirname, 'src'),
  })
);

根路径下新增route文件,并引入至App.js

import React from 'react';
import { HashRouter, Switch, Route, Redirect } from 'react-router-dom';
import Login from '@/pages/login';
import PageNotFount from '@/pages/404';
import Home from '@/pages/home';
import Details from '@/pages/details';

const routes = [
  {
    path: '/login',
    component: Login,
    exact: true,
  },
  {
    path: '/404',
    component: PageNotFount,
    exact: true,
  },
  {
    path: '/',
    component: Home,
    exact: true,
  },
  {
    path: '/home',
    component: Home,
    exact: true,
  },
  {
    path: '/details',
    component: Details,
    exact: true,
  },
];

export default function RoutesList() {
  return (
    <HashRouter>
      <Switch>
        {routes.map((route, index) => {
          return route && route.Redirect ? (
            <Redirect key={index} to={route.Redirect} />
          ) : (
            <Route key={route.path} {...route} />
          );
        })}
        <Redirect to="/404" />
      </Switch>
    </HashRouter>
  );
}

react-mobile's People

Watchers

kiki avatar

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.