简体   繁体   English

我的反应路线重定向到 localhost:3000 而不是它应该重定向到的页面

[英]My react route is redirecting to localhost:3000 and not the page it should redirect to

I have 2 components both are exactly the same.我有 2 个组件都完全相同。 one is redirected to when I click on a Navlink inside of my navbar that I created using react-bootstrap.当我单击使用 react-bootstrap 创建的导航栏中的 Navlink 时,将重定向到一个。 The other component that is exactly the same just redirects to localhost:3000 and not "./member" when I click on the html button that should redirect to that component.当我单击应该重定向到该组件的 html 按钮时,完全相同的另一个组件只是重定向到 localhost:3000 而不是“./member”。 Please help me.请帮我。

the html button and the function to redirect look like html 按钮和 function 重定向看起来像

import {Link, Route, withRouter, useHistory} from 'react-router-dom'
const Posts = (props) => {
  const dispatch = useDispatch();
    const history = useHistory();

    const getProfile = async (member) => {
     //   const addr = dispatch({ type: 'ADD_MEMBER', response: member })
        console.log(member)
        history.push('/member')
    
    }
    
  return (
      <div>
        <button onClick={() => getProfile(p.publisher)}>Profile</button> 

      </div>
  )
}

export default withRouter(Posts);

The routes.js looks like routes.js 看起来像

const Routes = (props) => {
  return (
      <Switch>

      <Route path="/member" exact component={Member} /> 

      </Switch>
    
  )
}

export default Routes

The component that I am trying to redirect to is exactly the same as one that is redirected to and working when I click on it from the navlink.我尝试重定向到的组件与当我从导航链接单击它时重定向到并正在工作的组件完全相同。 I have downgraded to history 4.10.1我已经降级到历史 4.10.1

My index.js is我的 index.js 是

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import 'bootstrap/dist/css/bootstrap.min.css';

import { Router, Route } from 'react-router-dom';
import * as history from 'history';
import * as serviceWorker from './serviceWorker';
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import rootReducer from './reducers'
const store = createStore(rootReducer)
const userHistory = history.createBrowserHistory();
ReactDOM.render(
    <Provider store = {store}>
        <Router history={userHistory}>
<BrowserRouter>


            <Route component={App} />
</BrowserRouter>

        </Router>
    </Provider>,
    document.getElementById('root'));


serviceWorker.unregister();

When I wrap the app route in the url goes to./member but it does not load.当我将应用程序路由包装在 url 中时,会转到./member 但它不会加载。

 <Switch>
      <Route path="/" exact component={app} /> 
      <Route path="/member" component={Member} /> 

      </Switch>

<button onClick={() => history.push(`/${p.publisher}`)}>Profile</button> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 localhost:3000 重定向到 localhost:3000/newpage - Redirecting localhost:3000 to localhost:3000/newpage react-full-page 阻止我的页面以特定 ID 打开,例如 http://localhost:3000/#someIdWhereIWantThePageToBeOpened - react-full-page prevents my page from opening in a certain ID like http://localhost:3000/#someIdWhereIWantThePageToBeOpened React 应用程序在 localhost:3000 上显示空白页面,但在 localhost:3001 上工作 - React app is showing blank page on localhost:3000 but working on localhost:3001 在React和Redux中删除页面/路由后进行重定向 - Redirecting after deleting page / route in React and Redux localHost 3000 显示空白页 - localHost 3000 showing blank page 无法将我的表单重定向到新的 html 页面。 它会转到 localhost:3000/confirm.html 而我希望它在新窗口中打开 confirm.html - Unable to redirect my form to a new html page. Its going to localhost:3000/confirm.html instead i want it to open confirm.html in a new window 当我想将 localhost:4000 重定向到 localhost:3000 时出现错误 CORS - Error CORS when i want redirecting localhost:4000 to localhost:3000 如何在React中创建重定向规则而不重定向到同一路由? - How to create redirect rules in React without redirecting to same route? React/NodeJS - Web 页面在 go at localhost:3000 时不工作 - React/NodeJS - Web page doesn't work when go at localhost:3000 React fetch(&#39;http:// localhost:3000 / profile /:id&#39;) - React fetch('http://localhost:3000/profile/:id')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM