3

I have a problem with a link in React Router. I used the mapping to generate layout with links:

  weeksData = weeks.map((weekData)=>{
    const link = 'manager/' + weekData.start + '/' + weekData.end;
    return(
        <li key={weekData.start}>
          <Link to={link}>
            <p>
              <b>{dateHandler.getVisualDate(weekData.start)} - {dateHandler.getVisualDate(weekData.end)}</b>
            </p>
          </Link>
        </li>
    );
  });

The problem is that when I click on elements the url is not replaced but it is being added like this:

manager/1530504000000/1531108800000 => manager/1530504000000/manager/1529899200000/1530504000000

Any idea how to fix that? I was thinking to use queries (I mean '?' in url) but I didn't manage to make it work as well.

1 Answer 1

4

Add an extra /.

const link = '/manager/' + weekData.start + '/' + weekData.end;

This ensures the link is at the web root.

Without the /, the url will be relative to the current page.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.