question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Slashes at end of URLs

See original GitHub issue

Is there a way to avoid the “/” characters getting added to my URLs?

In this sandbox, click on the /page1 or /page2 links and you will see the URL change to /page1/ or /page2/. Happens in my own app, too.

https://codesandbox.io/s/n7v5o7j310

All the code:

import React from "react";
import ReactDOM from "react-dom";
import { mount, route } from "navi";
import { Router, Link } from "react-navi";

import "./styles.css";

const routes = mount({
  "/": route({
    view: () => (
      <p>
        Home. Go to <Link href="/page1">page 1</Link> or{" "}
        <Link href="/page2">page 2</Link>.
      </p>
    )
  }),
  "/page1": route({
    view: () => (
      <p>
        Page 1. Go <Link href="/">home</Link> or to{" "}
        <Link href="/page2">page 2</Link>.
      </p>
    )
  }),
  "/page2": route({
    view: () => (
      <p>
        Page 2. Go <Link href="/">home</Link> or to{" "}
        <Link href="/page1">page 1</Link>.
      </p>
    )
  })
});

function App() {
  return (
    <div className="App">
      <Router routes={routes} />
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
squarismcommented, Jun 26, 2019

I was getting Error: Not implemented: window.scroll. Just for the boilerplate create-react-app “App doesn’t crash” type test. I have a test setup file that jest loads. It has a global.window variable to handle this and like session storage. I don’t know of a better solution than this but I got rid of that error @jdiamond by doing this. Jest runs without errors but I just got this working.

// setup.js - loaded by jest as part of setupFilesAfterEnv

// many other things like enzyme setup etc ...

global.window = {}
window.scroll = function () { }
// or window.scroll = () => { }

Maybe your project is slightly different, maybe this helps. 🎈

1reaction
lookfirstcommented, May 27, 2021

@lookfirst Would you be horrified to know that I googled this and found my own comment and used it two years later? 🌻

We code in javascript, nothing horrifies us anymore. =)

Read more comments on GitHub >

github_iconTop Results From Across the Web

When should I use a trailing slash in my URL? - Stack Overflow
A slash at the end of the URL makes the address look "pretty". A URL without a slash at the end and without...
Read more >
Should You Have a Trailing Slash at the End of URLs?
The trailing slash matters for most URLs. Conventionally, a trailing slash (/) at the end of a URL meant that the URL was...
Read more >
To slash or not to slash | Google Search Central Blog
This behavior is beneficial because it reduces duplicate content. In the particular case of redirects to trailing slash URLs, our search results will...
Read more >
Trailing Slashes and SEO - Best Practice Guide - Safari Digital
Historically, a trailing slash marked a directory and a URL without a trailing slash at the end used to mean that the URL...
Read more >
Trailing Slashes in URLs – What is the Preferred Style?
The addition of a slash at the end of a URL instructs the web server to search for a directory. This speeds the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found