简体   繁体   English

当我单击一个按钮时,页面不会在 React Javascript 中刷新

[英]When I click a button the page does not refresh in React Javascript

I created a page that when I click the shop button the URL is displayed on the url space but the page does not load onclick of the button我创建了一个页面,当我单击商店按钮时,URL 会显示在 url 空间上,但页面不会加载按钮的 onclick

import React from "react";
import {withRouter} from 'react-router-dom';

import './menu-item.styles.scss'

const MenuItem= ({title, imageUrl, size, history, linkUrl , match}) => (
    <div 
        className={`${size} menu-item`} 
        onClick = {() => history.push(`${match.url},${linkUrl}`)}>
        <div 
            className="background-image"
            style={{
            backgroundImage : `url(${imageUrl})`
            }}
        />
        <div className="content">
            <h1 className="title">{title.toUpperCase()}</h1>
            <span className="subtitle">SHOP NOW</span>
        </div>
    </div>
)

export default withRouter(MenuItem);

The page that is supposed to display is only shown when I refresh the page but when I click the button the url is displayed but not loaded.应该显示的页面仅在我刷新页面时显示,但当我单击按钮时,url 显示但未加载。

import React from 'react';
import {Switch, Route} from 'react-router-dom';
import './App.css';

import HomePage from './pages/homepage/home.component';
import ShopPage from './pages/shop/shop.components';
import Header from './components/header/header.component';

function App() {
  return (
    <div>
      <Header/>
      <Switch>
        <Route exact path='/' component={HomePage}/>
        <Route path='/shop' component={ShopPage}/>
      </Switch>
    </div>
  );
}

export default App;

import { NavLink } from 'react-router-dom';从 'react-router-dom' 导入 { NavLink };

    <NavLink 
        className={`${size} menu-item`} 
        to={linkUrl}>
        <div 
            className="background-image"
            style={{
            backgroundImage : `url(${imageUrl})`
            }}
        />
        <div className="content">
            <h1 className="title">{title.toUpperCase()}</h1>
            <span className="subtitle">SHOP NOW</span>
        </div>
    </NavLink>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM