javascript - Symfony and React router, no route found -
i using symfony3 , creating bundle using react.js using react-router.
the issue when use routing in react, if reload page symfony routing module send 'no route found"
my routes /admin index page , /admin/data next page.
when load page /admin good, click on link go /admin/data, works, react send me dynamically on it, when refresh (f5) page /admin/data, symfony intercept , try find routing in code , redirect /404 "no route found".
i know on angularjs, framework using ancors path "localhost://admin/#/data", seems easier manage react-router use "localhost://admin/data"
my symfony routing:
admin: path: /admin defaults: { _controller: bibundle:admin:default }
my react routing:
import { router, browserhistory } "react-router"; <router history={browserhistory}> <route path="/admin" component={app}> <indexroute components={{content: dashboardpage}} /> <route path="data/list" components={{content: datalistpage}} /> <route path="*" components={{content: _ => <h1>page not found.</h1>}} /> </route> </router>
my link on /admin page:
<link to={'/admin/data/list'}>data</link>
i thinking modify .htaccess redirect /admin/* /admin seems overkill issue.
i using apache2 server too.
edit
i have replaced browserhistory hashhistory
import { router, hashhistory } "react-router"; <router history={hashhistory}> <route path="/" component={app}> <indexroute components={{content: dashboardpage}} /> <route path="data/list" components={{content: datalistpage}} /> <route path="*" components={{content: _ => <h1>page not found.</h1>}} /> </route> </router>
it had result change path used in angularjs (or close enough), have /admin#/ , /admin#/data/list, symfony catch /admin , react-router catch #/ or #/admin/data
what think ? methodology ?
to make ajax routing accessible url directly (i.e. typing /admin/data
in browser url) without being redirected server-side, need make base route (the symfony route renders react application) taking parameter represents ajax routing.
to this, parameter must allow slashes, example:
admin: path: /admin/{reactrouting} defaults: { _controller: bibundle:admin:default, reactrouting: null } requirements: reactrouting: ".+"
for more complex routing, should @ fosjsroutingbundle you.
Comments
Post a Comment