admin管理员组文章数量:1323200
I am using Symfony3 and I am creating a bundle using React.js using itself react-router.
The issue is when I use the routing in react, if I reload the page the symfony routing module send 'No Route Found"
My routes are /admin for the index page and /admin/data for the next page.
When I load the page /admin everything is good, I click on the link to go to /admin/data, everything works, react send me dynamically on it, but now when I refresh (F5) the page /admin/data, Symfony intercept it and try to find the routing in its code and redirect to /404 "No Route Found".
I know on AngularJs, the framework is using ancors Path "localhost://admin/#/data", which seems easier to manage but react-router use "localhost://admin/data"
My symfony routing:
admin:
path: /admin
defaults: { _controller: BiBundle:Admin:default }
My React routing:
import { Router, browserHistory } from "react-router";
<Router history={browserHistory}>
<Route path="/admin" ponent={App}>
<IndexRoute ponents={{content: DashboardPage}} />
<Route path="data/list"
ponents={{content: DataListPage}} />
<Route path="*"
ponents={{content: _ => <h1>Page not found.</h1>}} />
</Route>
</Router>
My link on /admin page:
<Link to={'/admin/data/list'}>Data</Link>
I was thinking to modify my .htaccess to redirect all /admin/* to /admin but seems overkill for that issue.
I am using Apache2 server too.
EDIT
I have replaced browserHistory by hashHistory
import { Router, hashHistory } from "react-router";
<Router history={hashHistory}>
<Route path="/" ponent={App}>
<IndexRoute ponents={{content: DashboardPage}} />
<Route path="data/list"
ponents={{content: DataListPage}} />
<Route path="*"
ponents={{content: _ => <h1>Page not found.</h1>}} />
</Route>
</Router>
It had the result to change my path as it is used in AngularJs (or close enough), so now I have /admin#/ and /admin#/data/list, so symfony always catch /admin and react-router catch #/ or #/admin/data
What do you think ? Is it the good methodology ?
I am using Symfony3 and I am creating a bundle using React.js using itself react-router.
The issue is when I use the routing in react, if I reload the page the symfony routing module send 'No Route Found"
My routes are /admin for the index page and /admin/data for the next page.
When I load the page /admin everything is good, I click on the link to go to /admin/data, everything works, react send me dynamically on it, but now when I refresh (F5) the page /admin/data, Symfony intercept it and try to find the routing in its code and redirect to /404 "No Route Found".
I know on AngularJs, the framework is using ancors Path "localhost://admin/#/data", which seems easier to manage but react-router use "localhost://admin/data"
My symfony routing:
admin:
path: /admin
defaults: { _controller: BiBundle:Admin:default }
My React routing:
import { Router, browserHistory } from "react-router";
<Router history={browserHistory}>
<Route path="/admin" ponent={App}>
<IndexRoute ponents={{content: DashboardPage}} />
<Route path="data/list"
ponents={{content: DataListPage}} />
<Route path="*"
ponents={{content: _ => <h1>Page not found.</h1>}} />
</Route>
</Router>
My link on /admin page:
<Link to={'/admin/data/list'}>Data</Link>
I was thinking to modify my .htaccess to redirect all /admin/* to /admin but seems overkill for that issue.
I am using Apache2 server too.
EDIT
I have replaced browserHistory by hashHistory
import { Router, hashHistory } from "react-router";
<Router history={hashHistory}>
<Route path="/" ponent={App}>
<IndexRoute ponents={{content: DashboardPage}} />
<Route path="data/list"
ponents={{content: DataListPage}} />
<Route path="*"
ponents={{content: _ => <h1>Page not found.</h1>}} />
</Route>
</Router>
It had the result to change my path as it is used in AngularJs (or close enough), so now I have /admin#/ and /admin#/data/list, so symfony always catch /admin and react-router catch #/ or #/admin/data
What do you think ? Is it the good methodology ?
Share Improve this question edited Oct 11, 2019 at 0:35 chalasr 13.2k5 gold badges43 silver badges83 bronze badges asked Mar 17, 2016 at 10:44 CifrenCifren 3581 gold badge4 silver badges15 bronze badges1 Answer
Reset to default 8To make your AJAX routing accessible from url directly (i.e. typing /admin/data
in browser URL) without being redirected server-side, you need to make your base route (the Symfony route that renders your React application) taking a parameter that will represents your AJAX routing.
To do this, the parameter must allow slashes, example:
admin:
path: /admin/{reactRouting}
defaults: { _controller: BiBundle:Admin:default, reactRouting: null }
requirements:
reactRouting: ".+"
For a more plex routing, you should look at the FOSJsRoutingBundle that could help you.
本文标签: javascriptSymfony and React routerno route foundStack Overflow
版权声明:本文标题:javascript - Symfony and React router, no route found - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742120366a2421666.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论