React 路由

React(五) —— 路由的使用 📍路由是根据不同的 url 地址显示不同的内容或页面📍一个针对React而设计的路由解决方案,可以友好的帮助解决React components到URL之间的同步映射关系。 阅读详情

 React 路由通常使用 react-router 库来实现,它是一个功能强大的库,用于在 React 应用程序中实现客户端路由。以下是关于如何在 React 中使用 React Router 的详细说明:

安装 React Router

首先,你需要安装 react-router-dom 包,这是用于在浏览器环境中实现路由的包。

npm install react-router-dom

基本用法

以下是使用 React Router 设置基本路由的步骤和示例代码。

1. 创建基础路由组件

首先,创建一些简单的组件,它们将被路由渲染。

实例

import React from 'react';

const Home = () => {
  return <h2>Home</h2>;
};

export default Home;

// About.js
import React from 'react';

const About = () => {
  return <h2>About</h2>;
};

export default About;

// Contact.js
import React from 'react';

const Contact = () => {
  return <h2>Contact</h2>;
};

export default Contact;

2. 设置路由

在你的主应用组件中,使用 react-router-dom 的组件来设置路由。

实例

import React from 'react';
import ReactDOM from 'react-dom/client';
import {
  BrowserRouter as Router,
  Routes,
  Route,
  Link
} from 'react-router-dom';

import Home from './Home';
import About from './About';
import Contact from './Contact';

const App = () => {
  return (
    <Router>
      <div>
        <nav>
          <ul>
            <li>
              <Link to="/">Home</Link>
            </li>
            <li>
              <Link to="/about">About</Link>
            </li>
            <li>
              <Link to="/contact">Contact</Link>
            </li>
          </ul>
        </nav>
        <Routes>
          <Route path="/" element={<Home />} />
          <Route path="/about" element={<About />} />
          <Route path="/contact" element={<Contact />} />
        </Routes>
      </div>
    </Router>
  );
};

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);

嵌套路由

React Router 允许你创建嵌套路由,这样可以在一个组件内渲染更多的路由。

实例

// Dashboard.js
import React from 'react';
import { Link, Outlet } from 'react-router-dom';

const Dashboard = () => {
  return (
    <div>
      <h2>Dashboard</h2>
      <nav>
        <ul>
          <li>
            <Link to="profile">Profile</Link>
          </li>
          <li>
            <Link to="settings">Settings</Link>
          </li>
        </ul>
      </nav>
      <Outlet />
    </div>
  );
};

export default Dashboard;

实例

// Profile.js
import React from 'react';

const Profile = () => {
  return <h2>Profile</h2>;
};

export default Profile;

实例

// Settings.js
import React from 'react';

const Settings = () => {
  return <h2>Settings</h2>;
};

export default Settings;

在主应用组件中设置嵌套路由:

实例

import React from 'react';
import ReactDOM from 'react-dom/client';
import {
  BrowserRouter as Router,
  Routes,
  Route,
  Link
} from 'react-router-dom';

import Home from './Home';
import About from './About';
import Contact from './Contact';
import Dashboard from './Dashboard';
import Profile from './Profile';
import Settings from './Settings';

const App = () => {
  return (
    <Router>
      <div>
        <nav>
          <ul>
            <li>
              <Link to="/">Home</Link>
            </li>
            <li>
              <Link to="/about">About</Link>
            </li>
            <li>
              <Link to="/contact">Contact</Link>
            </li>
            <li>
              <Link to="/dashboard">Dashboard</Link>
            </li>
          </ul>
        </nav>
        <Routes>
          <Route path="/" element={<Home />} />
          <Route path="/about" element={<About />} />
          <Route path="/contact" element={<Contact />} />
          <Route path="/dashboard" element={<Dashboard />}>
            <Route path="profile" element={<Profile />} />
            <Route path="settings" element={<Settings />} />
          </Route>
        </Routes>
      </div>
    </Router>
  );
};

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);

动态路由

可以在路径中包含动态参数。

实例

// User.js
import React from 'react';
import { useParams } from 'react-router-dom';

const User = () => {
  const { userId } = useParams();
  return <h2>User ID: {userId}</h2>;
};

export default User;

在主应用组件中设置动态路由:

实例

import React from 'react';
import ReactDOM from 'react-dom/client';
import {
  BrowserRouter as Router,
  Routes,
  Route,
  Link
} from 'react-router-dom';

import Home from './Home';
import About from './About';
import Contact from './Contact';
import Dashboard from './Dashboard';
import Profile from './Profile';
import Settings from './Settings';
import User from './User';

const App = () => {
  return (
    <Router>
      <div>
        <nav>
          <ul>
            <li>
              <Link to="/">Home</Link>
            </li>
            <li>
              <Link to="/about">About</Link>
            </li>
            <li>
              <Link to="/contact">Contact</Link>
            </li>
            <li>
              <Link to="/dashboard">Dashboard</Link>
            </li>
            <li>
              <Link to="/user/1">User 1</Link>
            </li>
            <li>
              <Link to="/user/2">User 2</Link>
            </li>
          </ul>
        </nav>
        <Routes>
          <Route path="/" element={<Home />} />
          <Route path="/about" element={<About />} />
          <Route path="/contact" element={<Contact />} />
          <Route path="/dashboard" element={<Dashboard />}>
            <Route path="profile" element={<Profile />} />
            <Route path="settings" element={<Settings />} />
          </Route>
          <Route path="/user/:userId" element={<User />} />
        </Routes>
      </div>
    </Router>
  );
};

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);

404 页面

可以使用 React Router 提供的 Navigate 组件来实现 404 页面重定向。

实例

import React from 'react';
import ReactDOM from 'react-dom/client';
import {
  BrowserRouter as Router,
  Routes,
  Route,
  Link,
  Navigate
} from 'react-router-dom';

import Home from './Home';
import About from './About';
import Contact from './Contact';
import Dashboard from './Dashboard';
import Profile from './Profile';
import Settings from './Settings';
import User from './User';

const NotFound = () => {
  return <h2>404 Page Not Found</h2>;
};

const App = () => {
  return (
    <Router>
      <div>
        <nav>
          <ul>
            <li>
              <Link to="/">Home</Link>
            </li>
            <li>
              <Link to="/about">About</Link>
            </li>
            <li>
              <Link to="/contact">Contact</Link>
            </li>
            <li>
              <Link to="/dashboard">Dashboard</Link>
            </li>
            <li>
              <Link to="/user/1">User 1</Link>
            </li>
            <li>
              <Link to="/user/2">User 2</Link>
            </li>
          </ul>
        </nav>
        <Routes>
          <Route path="/" element={<Home />} />
          <Route path="/about" element={<About />} />
          <Route path="/contact" element={<Contact />} />
          <Route path="/dashboard" element={<Dashboard />}>
            <Route path="profile" element={<Profile />} />
            <Route path="settings" element={<Settings />} />
          </Route>
          <Route path="/user/:userId" element={<User />} />
          <Route path="*" element={<Navigate to="/" replace />} />
        </Routes>
      </div>
    </Router>
  );
};

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);

小结

通过使用 React Router,你可以轻松地在 React 应用中实现路由功能,包括基本路由、嵌套路由、动态路由以及 404 页面等。通过这种方式,你可以创建一个功能强大且用户友好的单页应用程序 (SPA)。

React (三) 根据定义的主题,切换组件的效果在src下添加theme.js2. 给指定的组件添加主题3. 这样包裹进去的所有组件都可以使用theme里定义的css,这里只有一个Button组件,我们就在该组件的css里使用。 阅读详情

相关推荐

react路由篇

嵌套路由是指将一个路由配置嵌套在另一个路由配置中的情况。通过嵌套,我们可以在应用中创建更复杂的页面结构,使得页面的层次关系更加清晰。首先抽象路由表,之后通过递归进行求解子路由,这里只显示两层路由,实际上可以使用 一个递归函数递归出路由来,如下所示path: "/",},path: "/",},}]},},return (return (return (}):null}})

m0_54864716的博客 4309

React 路由配置

3, 创建路由文件src/router/index.js, 导入需要路由跳转的组件, 并导出路由配置数组。2, 在入口文件 src/index.js中,从路由模块导入工具组件Router ,并包裹根组件。2, 在入口文件 src/index.js中,从路由模块导入工具组件Router ,并包裹根组件。2, 在入口文件 src/index.js中,从路由模块导入工具组件Router ,并包裹根组件。2, 创建路由文件src/router/index.jsx, 导入根组件和需要路由跳转的组件。

We_990528的博客 4724

使用ReactJs React-Bootstrap 构建网站(2):路由器控制

为什么BootStrap效果显示不出来 因为版本不对的原因,React-BootStrap与BootStrap版本要相配。 本人取了如下的匹配 “bootstrap”: “^4.6.0”, “react-bootstrap”: “^1.5.2”, 这个问题困扰了好长时间,网上没有现成的解答,后来看了它提供的示例,才明白。 示例在如下链接里 https://github.com/react-bootstrap/code-sandbox-examples/blob/master/README.md 路由器的

fenboo9416的博客 390

React项目-路由配置

在src/创建一个router.js文件(目录结构可以自定义)

StupidlyGrass的博客 3004

抖音小程序开发 唤起收银台支付(可以选择支付宝APP支付或微信H5支付)

什么都别说,先看效果: 字节跳动也开放了小程序给商家接入,可以在旗下APP如抖音、今日头条、今日头条极速版等应用中即点即用,基于庞大的数亿用户量为其引流,帮助商家获取用户流量,销售商品,其模式和微信小程序差不多。 1、后台管理地址: https://developer.toutiao.com/ 2、开发文档地址: https://developer.toutiao.com/dev/cn/min...

悟空码字的博客 1万+

python提取图片中的文字写入excel文件,并打包为exe可执行文件

python提取图片中的文字写入excel文件,并打包为exe可执行文件

liqiang12689的博客 990

Reactjs路由

BrowserRouter:浏览器的路由方式,也就是在开发中最常使用的路由方式 React Router 是建立在history上的。 即:一个history知道如何去监听浏览器地址栏的变化,并解析这个URL转化为 location 对象,然后 router 使用它匹配到路由,之后正确的渲染出对应的组件。 来一些例子解析一下 首先在终端安装 yarn add react-router-dom -S...

weixin_45348067的博客 284

鸿蒙子系统解读-分布式软总线子系统初步研究(下)

鸿蒙子系统解读-分布式软总线子系统初步研究(下) 本文作者:江苏润和软件股份有限公司 郎建中 3.2. 数据传输 上一节我们看了PublishService()函数的代码实现过程。被发现端发布服务后,软总线回调发布成功的函数中,被发现端需要使用CreateSessionServer()来创建会话的服务器等待发现端的连接创建会话。下面我们就来分析CreateSessionServer()函数的实现过程。 数据传输部分的代码位于foundation/communication/services/softbus

weixin_47070198的博客 3096

reactjs路由:react-router-dom安装及路由代码示例

这只是 React 路由的基本用法示例,React Router 还提供了更多功能和配置选项,如嵌套路由、路由参数等。React Router 是一个基于 React 的第三方库,提供了一组用于处理路由的组件和 API。这样,当用户点击导航栏中的链接时,React 路由会根据当前的 URL 路径匹配对应的路由规则,并渲染相应的页面组件。接下来,我们可以在应用程序的根组件中设置路由。在上面的示例中,我们首先导入了所需的组件和 API,包括。组件来定义路由规则,并在匹配到对应路由时渲染相应的组件。

学亮编程手记 294

“华为”云桌面系统声音比较小,如何调大?

调整操作系统声音 开启云桌面,登录账户之后,进入操作系统,鼠标左键点击右下角的声音图标,把声音调到最大(如下图); 可以考虑使用浏览器在线听音乐,确定声音的音量! 如果只是耳麦声音小,可以鼠标右键点击声音图标,选择录音设备(R),如下图: 点击“录音设备(R)”后进入,鼠标右键点击“麦克风”选择属性,将侦听级别调至最大,确定! 调整华为云终端声音(软设置) 将鼠标移至桌面的顶端中间位置,打开如下图的样式图标,鼠标左键点击“主页”; 点击“主页”之后,将回到云桌面的终端操作界面,

shunchang的专栏 2345

无需UMAT:基于Abaqus内置模型实现形状记忆聚合物结构的热-力耦合仿真

本文详细介绍了如何利用Abaqus内置模型实现形状记忆聚合物(SMP)的热-力耦合仿真,无需编写复杂的UMAT子程序。通过广义Maxwell模型和Neo-Hookean模型的组合应用,结合完整的热-力耦合分析流程,帮助工程师高效模拟SMP的形状记忆行为。文章还提供了工程应用案例和常见问题解决方案,为相关领域的研究和设计提供实用指导。

weixin_34005090的博客 118

从零开始学习ReactJS -- 02 -- 然后要把路由配置起来才能区分页面啊!

从零开始学习React - 02 学习路由配置 查询度娘, react的路由配置有且仅有一种 react-router 、 react-router-dom 经过比较,觉得react-router-dom 更好一些,所以使用react-router-dom 安装react-router-dom npm install react-router-dom 执行完成后安装完成 开始配置 我没有找到react-router-dom的中文官方文档,只能拼凑这看教程来进行学习 单独在src下建立router文件夹进行

GASG的博客 218

工程制图习题集张大庆课后习题答案解析

所以,我想向大家求助,希望能得到一些学习资料、学习方法和学习经验,帮助我更好地理解和掌握这门课程。在寻找学习资料的过程中,我发现了一款叫做资小料的APP,它里面有很多关于工程制图的学习资料,包括视频教程、习题解答和考试真题等。通过使用资小料,我逐渐掌握了工程制图的基本理论和方法,解决了很多学习中遇到的问题。在这里,我想推荐给和我一样在学习《工程制图习题集》这门课的同学们,希望大家也能从这款APP中受益,共同进步。上传者: 『Consentesdei』蒼迷穀。出版社: 清华大学出版社。

weixin_58833001的博客 929

reactjs 动态路由 动态导入组件 require和react-loadable 传入变量

1.常规导入组件 常规的导入组件需要在文件开始就将导入的组件写死,如下 import xxx from 'xxx' 现在我需要通过后端返回的数组动态的生成路由,因此在不知道后端返回的情况下,不知道需要导入哪些组件,就需要根据后端返回的组件路径,动态导入组件, 方法一:require 后端返回的数据如下: [{ path: '/login', component: 'Login' }] 可以看见,组件为一个字符串路径。 routes.js如下: /** * 根据数组生成路由数组,主要是根

qq_36706941的博客 2657

ZYNQ平台AXI DMA传输避坑指南:如何快速定位‘errors:200‘等中断故障

本文详细解析了ZYNQ平台AXI DMA传输中常见的'errors:200'等中断故障,提供了从寄存器解析到压力测试的完整解决方案。通过深入分析XILINX_DMA中断机制、错误分类及五步排查法,帮助开发者快速定位并解决DMA传输问题,提升系统稳定性与性能。

weixin_29159613的博客 446

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

reactjs18 中使用路由技巧

react18 版本中,路由的用法发生了变化,react18 版本中,路由由 react-router-dom 包提供。与 react-router 包不同的是,react-router-dom 包提供了 createBrowserRouter 方法,该方法可以创建路由对象。总之,react-router6.x 版本的用法越来越接近 vue3.x 版本,互相借鉴互相学习,vue3 抄 react 的 hooks,react 18抄 vue 的 router 使用方式。

峰会路转的博客 1074

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

React微前端路由reactjs-interview-questions:路由隔离与通信机制

在现代Web应用开发中,微前端(Micro Frontend)架构已成为大型应用的主流解决方案。随着业务复杂度的增加,单一团队维护整个前端应用变得越来越困难。微前端通过将大型应用拆分为多个独立开发、独立部署的子应用,实现了团队自治和技术栈的灵活性。 然而,微前端架构也带来了新的挑战,特别是在路由管理方面。传统的单页面应用(SPA)路由方案无法直接适用于微前端场景,需要设计专门的路由隔离与通信机制...

gitblog_01107的博客 703

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

React之路由

路由 安装 先用create-react-app生成一个react项目 进入该项目 安装包 react-router-dom 分为2种模式:hash(哈希),browser(浏览器的那种,H5提供的API) 认识路由 路由模块,需要一个路由容器,标识着使用了那种模式的路由 import {容器} from &quot;react-router-dom&quot;; // 容器中存放的就是路由:HashRouter...

努力让自己幸运... 1万+

ReactJS 101路由实战:如何使用React Router构建单页应用的7个技巧

在当今前端开发领域,**React Router**已成为构建现代化**单页应用**(SPA)的黄金标准。作为React生态系中最重要的路由管理库,它让开发者能够轻松创建无缝的用户体验,实现页面间的平滑切换而无需重新加载。本文将分享7个实用技巧,帮助初学者快速掌握React Router的核心概念,构建高效的单页应用。 React Router架构图 ## 📋 技巧一:理解React Rou

gitblog_00208的博客 426

React路由

用于获取 URL 路径中的参数。返回一个对象,其中包含当前路由路径中定义的动态参数。特点声明式导航编程式导航实现方式使用或组件使用或history灵活性相对固定,更加直观高度灵活,支持条件导航适用场景静态链接动态路由逻辑和条件导航状态管理自动处理活动状态需手动管理状态HashRouter:适合简单应用,易于配置,但在 SEO 和 URL 美观性方面存在限制。:适合复杂应用,支持现代特性,但需要额外的服务器配置以避免 404 错误。特点HashRouter。

2301_76662406的博客 3873

【React】 react路由

react-route-dom 6

weixin_43872912的博客 1871

Reactjs之静态路由、动态路由以及Get传值以及获取

1、新增知识点 /* react路由的配置: 1、找到官方文档 https://reacttraining.com/react-router/web/example/basic 2、安装 cnpm install react-router-dom --save 3、找到项目的根组件引入react-router-dom import { B...

weixin_30677073的博客 439

reactjs router 4 (react-router-dom)使用嵌套路由遇到的问题

在使用react router 4 (react-router-dom)时遇到了好多问题,折腾了快两天才弄清楚。这主要是自己急于求成,没有读官方的文档。回头想想,自己折腾的时间或许比读完官方文档的时间还长。下面说遇到的问题。 1. 只使用Route会渲染所有匹配的路径。看下面代码:<Route path='/' component={Com1}/> <Route path='/app' compo

xgbm_k的专栏 8737

React多级路由 React子路由

React多级路由 React子路由设置 新建一个Home.jsx文件 和Home.css文件 css文件内容就不写了 Home 文件内容如下 为了解决点击Link时,路由变化而子路由页面未变化,所以需要在窗口中加入key属性。 import "./Home.css" import React,{ Component } from "react"; import { BrowserRouter...

yj6232779的博客 3327

react路由嵌套路由及路由传参

因为react的嵌套路由跟vue比就像屎一样 不好写 所以在使用的时候建议使用react-router-config来配置路由 会相对轻松 第一步 先安装路由依赖 yarn add react-router-dom --save yarn add react-router-config --save 第二部 配置路由文件 新建一个routes.js文件 新建pages文件夹和home组件about组件及page2组件 import React from 'react'; impo.

wjw0125的博客 3168
上一篇: chromedriver版本下载地址汇总chromedriver所有版本下载地址汇总国内源下载
下一篇: React Memo
听风二里
博客等级 码龄3年 4351粉丝 412原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址