SO中文参考
首页
(current)
程序语言
c
java
python
c++
go
javascript
swift
c#
操作系统
linux
ubuntu
centos
unix
数据库
oracle
mysql
mongodb
postgresql
框架
node.js
angular
react-native
avalon
django
twisted
hadoop
.net
移动开发
android
ios
搜索
如何在React和symfony项目中管理路由?{% 块标题 %}</desc> <question vote="0"> <p>我使用 React 对 symfony 中的页面进行 vite 操作:</p> <p>这是基础:</p> <pre><code><!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>{% block title %}Welcome!{% endblock %}</title> {# Run `composer require symfony/webpack-encore-bundle` and uncomment the following Encore helpers to start using Symfony UX #} <link rel="shortcut icon" type="image/x-icon" href="{{ asset('images/Logo 2.png') }}"> <meta name="viewport" content="width=device-width, initial-scale=1"> {% block stylesheets %} {{ vite_entry_link_tags('app') }} {% endblock %} <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet"> </head> <body> {% block body %}{% endblock %} {% block javascripts %} {{ vite_entry_script_tags('app') }} {% endblock %} </body> </html> </code></pre> <p>这是树枝:</p> <pre><code>{% extends 'base.html.twig' %} {% block title %}Reseau Sociaux{% endblock %} {% block body %} <div id="app"></div> {% endblock %} </code></pre> <p>这是控制器:</p> <pre><code>/** * @Route("/reseau-sociaux", name="reseau-sociaux_home") * @IsGranted("ROLE_USER") */ public function reseauSociaux(Request $request) { return $this->render('reseauSociaux/reseauSociaux.html.twig'); } </code></pre> <p>这是我的反应:</p> <pre><code>import React from "react"; import { createRoot } from 'react-dom/client'; import Actualite from './pageActualite/Actualite' import './styles/app.css'; import { BrowserRouter, Routes, Route } from "react-router-dom"; import ProfilUser from "./otherPages/ProfilUser/ProfilUser"; const App = () => { return ( <BrowserRouter> <Routes> <Route path="reseau-sociaux" element={<Actualite />}/> <Route path="/reseau-sociaux/profil" element={<ProfilUser />}/> </Routes> </BrowserRouter> ); } const rootElement = document.querySelector('#app'); const root = createRoot(rootElement); root.render(<App />); </code></pre> <p>问题是<strong>route</strong>,react-router-dom运行良好,但是如果我刷新页面,错误是:找不到路由,来自symfony的错误。例如,如果我刷新 /reseau-sociaux/profile 页面,我会收到错误,因为我的 symfony 中没有路由 /reseau-sociaux/profil。</p> <p>我也有其他树枝页面,但它们效果很好</p> </question> <answer tick="false" vote="0"> <p>当然...如果你将路线从<pre><code>/reseau-sociaux</code></pre>延伸到<pre><code>/reseau-sociaux/profil</code></pre>,那就是symfony路线不匹配。你必须 symfony 告诉你的路线可以有子路径。</p> <p>您可以更改路由参数以匹配子路径,例如</p> <pre><code>/** * @Route("/reseau-sociaux/{sub}", name="reseau-sociaux_home", requirements={"sub"=".+"}) * @IsGranted("ROLE_USER") */ public function reseauSociaux(Request $request, ?string $sub = null) { return $this->render('reseauSociaux/reseauSociaux.html.twig'); } </code></pre> </answer> </body></html>
问题描述
投票:0
回答:0
reactjs
symfony
twig
react-router-dom
vite
最新问题
在 dplyr 中使用 OR 来连接任意一组列
如何获取网络DateTime.Now()?
将一行 Delphi 代码行转换为 C++
PrimeNG TreeSelect:编程选择不会传播
SAP HANA 查询 - 基于字段的位置
Wordpress升级后数据库版本问题
检查udp套接字是否连接
Android Studio 在最小化窗口或构建/运行项目时关闭我的项目
强力查询:仅将一列转换为标题,并将另一列的值引入相应列
通过类和方法名称发现 JUnit5 参数化测试会抛出 org.junit.platform.commons.PreconditionViolationException
如何从静态调用的对象转而调用trate方法?
为什么 git 不允许我克隆这个存储库?
mat-table Angular 中的动态 matHeaderRowDef
需要一个左括号,后跟一组值。 (位置 0 处“”附近)
根据 Angular 中的验证模式显示错误消息
JMS 性能
ReactPlayer 使用自定义按钮时会重新渲染
如何使用Python将按钮数组链接到变量数组?
使用 NGINX 作为 NodeJs 应用程序时 https 响应非常慢
我收到“访问被拒绝:DriveApp”。但所有权限都被允许
© www.soinside.com 2019 - 2024. All rights reserved.