【问题标题】:React router changes url but not page loadingReact 路由器更改 url 但不更改页面加载
【发布时间】:2020-04-07 08:32:42
【问题描述】:

// this is my index.js
import React, {  } from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import store from "./store/configureStore";
import { Router } from "react-router";

import "./index.css";
import App from "./App";
import history from "./history";

// append app to dom
ReactDOM.render(
    <Provider store={store}>
      <Router  history={history}>
        <App  />
        </Router>
    </Provider>,
  document.getElementById("root")
 
);

//this is my app.js
import React, { Component } from 'react';
import { Route, Switch, BrowserRouter } from 'react-router-dom';
import Inscription from "../src/pages/inscription";


class App extends Component {

  render() {
 
    return (  
     < BrowserRouter>
      <Route exact path="/" component={Inscription} />
      </ BrowserRouter>   
    );
  }
}
export default (App);

我正在更改视图以响应路由。看来我已经尝试了所有可以谷歌搜索但没有运气的东西。页面贴上但不加载 请同一个可以帮助我:(

【问题讨论】:

  • 能否添加相关的路由代码?就目前而言,您遇到的问题已经有很多关于它的帖子,比如这个:stackoverflow.com/questions/43351752/…
  • 欢迎来到 SO。不幸的是,这还不够信息。发布您的所有相关代码,以便我们进行调试和帮助。
  • 能否将代码添加到您的问题中,而不是作为答案?您也可以编辑问题。谢谢!
  • 我重新发布该出版物可以帮助我吗

标签: reactjs react-router history react-dom


【解决方案1】:

尝试从 App 组件中删除 BrowserRouter。您已经在 index.js 中提供了 Router。另外,如果你想定义多个路由,你必须使用switch

<Switch>
    <Route exact path="/" component={Inscription} />
    <Route exact path="/hello" component={HelloComponent} />
<Switch>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 2022-01-10
    • 2021-08-10
    • 2018-07-25
    • 1970-01-01
    • 2019-11-19
    相关资源
    最近更新 更多