无法让这个路由器工作。这就是我所拥有的:
Symfony控制器看起来像这样:
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request, $slug = null)
{
// replace this example code with whatever you need
return $this->render('base.html.twig', array(
'base_dir' => realpath($this->container->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
));
}
/**
* @Route("/projects", name="projects")
*/
public function projectsAction(Request $request)
{
// replace this example code with whatever you need
return $this->render('base.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
]);
}
此操作都呈现相同的twig页面,该页面呈现此反应组件:
import React from 'react';
import { BrowserRouter, Route, Link, Switch} from 'react-router-dom'
import Home from './home.jsx';
import Projects from './projects.jsx';
class Base extends React.Component{
render() {
return (
Blablablabla......
a menu and some stuff blablablabla....
<div className="row" id="mainContent">
<BrowserRouter>
<Switch>
<Route exact path='/' component={Home}/>
<Route path='/projects' component={Projects}/>
</Switch>
</BrowserRouter>
</div>
);
}
};
然后我有这些组件,我试图路由到:
import React from 'react';
import ContentBox from './contentBox.jsx';
class Home extends React.Component{
render() {
return (
<h1>Välkommen</h1>
);
}
};
export default Home;
import React from 'react';
import ContentBox from './contentBox.jsx';
class Projects extends React.Component{
render() {
return (
<h1>Projekt</h1>
//<ContentBox text="Projekt vettu"/>
);
}
};
export default Projects;
我希望home-component在/ projects上呈现/和项目组件。但是没有任何东西呈现在基本组件内部。但是,如果我删除了“确切的”&#39;归属路线中的属性。主组件将呈现,但随后它也会呈现/项目,而项目组件根本不会呈现。
怎么回事?
我也试过在/ -path(home)上渲染项目组件,然后它会渲染。所以组件似乎没有问题;它必须是路由,我无法理解为什么。
有没有人有想法?