Answer the question
In order to leave comments, you need to log in
How to make friends react-router-dom with symfony backend?
there is a REACT code like this
import React from 'react'
import ReactDOM from 'react-dom'
import createClass from 'create-react-class'
import {BrowserRouter as Router ,Route ,Link ,browserHistory ,Switch} from 'react-router-dom'
// Pages
const Home = () => (
<div>
<h1>Welcome to Home page !</h1>
</div>
);
const News = () => (
<div>
<h1>this page News !</h1>
</div>
);
// config Route
const Main = () => (
<main>
<Switch>
<Route exact path='/' component={Home}/>
<Route path='/news' component={News}/>
</Switch>
</main>
);
const Header = () => (
<header>
<nav>
<ul>
<li><Link to='/'>Home</Link></li>
<li><Link to='/news'>News</Link></li>
</ul>
</nav>
</header>
);
// render
const App = () => (
<div>
<Header />
<Main />
</div>
);
ReactDOM.render((
<Router>
<App />
</Router>
), document.getElementById('root'));
class TController extends Controller
{
/**
* @Route("/", name="home")
*/
public function home()
{
return $this->render('content/home.html.twig', [
'controller_name' => 'TController',
]);
}
/**
* @Route("/news", name="news")
*/
public function news()
{
return $this->render('content/news.html.twig', [
'controller_name' => 'TController',
]);
}
}
Answer the question
In order to leave comments, you need to log in
You need to use an API approach. Forget templates. Your backend only responds with json to your requests (get/post/put/delete)
Routing moves entirely to the client.
similar questions:
Explain in simple terms how React communicates with a backend like Java or PHP?
What to use on the backend for SPA applications?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question