W
W
Wales2018-07-20 04:34:11
React
Wales, 2018-07-20 04:34:11

Preact/React how to implement links without displaying the href attribute?

Hello!
Perhaps I haven’t studied React too well and don’t know everything, but even armed with Google, github and various resources, I couldn’t understand how to implement this:
There is a curious.ru mail project made using PReact
And there is a menu of three links. Only now they are divs and do not have an href attribute:

<nav class="_1XOC9SnsacmiKGPjY05_Ib _3JGVJkMDUWDI2QgLrC1_2u">
<div class="_2bR2iQn7qZOC2HQhzPMjGr">Истории</div>
<div class="_2bR2iQn7qZOC2HQhzPMjGr">Билборд</div>
<div class="_2bR2iQn7qZOC2HQhzPMjGr">Избранное</div>
</nav>

Since react-router and preact-router do not have such huge differences, the question arises: how, at least in theory, can such linking be implemented?
Thanks in advance for your reply

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
davidnum95, 2018-07-20
@Wales

Through history:

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

const Nav = ({ history }) => (
 <nav>
  <div onClick={() => history.push('/')}>Истории</div>
  <div onClick={() => history.push('/bilboard')}>Билборд</div>
  <div onClick={() => history.push('/loved')}>Избранное</div>
 </nav>
)

export default withRouter(Nav);

A
Anton Spirin, 2018-07-20
@rockon404

import { Link } from "react-router-dom";

const Nav = () => (
  <nav>
    <Link to="/">Истории</Link>
    <Link to="/bilboard">Билборд</Link>
    <Link to="/loved">Избранное</Link>
  </nav>
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question