K
K
kirillleogky2020-12-29 12:19:38
JavaScript
kirillleogky, 2020-12-29 12:19:38

How can you render the same component for different URLs?

I'm using Next.js
Project structure:
5feaf3f3e3e96815649938.png

How do I render the same component when writing data URLs: ' localhost:3000/hakkimizda ', ' localhost:3000/cerez-politikasi ', ' localhost:3000/kullanim-kosullari '

My component :

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';

import { withRouter } from 'next/router';

class InfoPage extends Component {
    render() {
        return <div className="info-page">
            <div className="info-page__header">
            </div>
        </div>;
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(withRouter(InfoPage));


How can I open the same component at different URLs (no related paths like ' localhost:3000/static-page/hakkimizda ') in Next.js ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Zenkovich, 2020-12-30
@JamesHatfield

I don't know how correct this is, but I did it and it worked. Created several routes with different urls and specified the same component in the Render method

<Route path='/path1' render={ ()=> <ComponentName />} />
<Route path='/path2' render={ ()=> <ComponentName />} />
<Route path='/path3' render={ ()=> <ComponentName />} />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question