[英]react-router-dom gives me 404
I started adding routes to my app, the problem is that even after I render them I cannot access them (get a 404). 我开始将路由添加到我的应用程序,问题是即使渲染它们后,我也无法访问它们(获取404)。 I tried this , this and this , but I cannot make it work.
我尝试了这个 , 这个和这个 ,但是我无法使其工作。 This is my index
这是我的索引
import React from 'react'
import ReactDOM from 'react-dom';
import App from './containers/App';
import { BrowserRouter } from 'react-router-dom';
import './index.css';
const app = (
<BrowserRouter>
<App />
</BrowserRouter>
);
ReactDOM.render(app, document.getElementById('root'));
and my App.jsx
is just 而我的
App.jsx
只是
import React, { Component } from 'react';
import {Route, Switch} from 'react-router-dom';
class App extends Component {
render() {
return (
<div>
<Switch>
<Route exact path = '/foo' render = {() => <h1>foo</h1>} />
<Route exact path = '/' render = {() => <h1>Home</h1>} />
</Switch>
<a href = '/foo'>Go to foo</a>
</div>
)
}
}
export default App;
In theory, if I click on the anchor tag, I should redirected to the foo
path, but instead I get a 404. Any suggestion is greatly appreciated 从理论上讲,如果单击锚标记,则应重定向到
foo
路径,但得到的却是404。非常感谢任何建议
您可以从react-router导入{Link},它会提供一个标签,您可以重定向
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.