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.

problem adding a new route to the file routes.json

See original GitHub issue

Hi, guys, I have downloaded your project ( very good ) and I started playing around with him, I was trying to add new functionality, and in the point of adding the new route, it gives me an error, I can’t add a new route constant to the file routes.json, I don’t know why but it doesn’t work when I use the new route, any advice?

Prerequisites

  • Using yarn
  • Using node 10.x
  • Using an up-to-date master branch
  • Using latest version of devtools. See wiki for howto update
  • Link to stacktrace in a Gist (for bugs)
  • For issue in production release, devtools output of DEBUG_PROD=true yarn build && yarn start
  • Tried solutions mentioned in #400

Expected Behavior

Well my new route should work, but instead, the app doesn’t show the main screen.

Current Behavior

The app doesn’t show the home page

Possible Solution

Steps to Reproduce (for bugs)

  1. Change the routes.sjon with this code : { “HOME”: “/”, “COUNTER”: “/counter”, “PEPE”: “/customer” }

2.Add to the routes.tsx with this code import CustomerPage from ‘./containers/CustomerPage’;

<Route exact path={“/customer”} component={CustomerPage} />

  1. Of course, you need to create a new component called CustomerPage, just take the home component and renamed and put inside it a different text from the home screen.

  2. I have added a toolbar from material UI that works perfectly, I’m going to upload my project with this link and you can see what I say.

Context

I’m trying to create an app and i need to add new routes and new screens to the project

Your Environment

  • Node version : 12.18.0
  • Version or Branch used : last one
  • Operating System and version : Windows 10
  • Link to your project : my project is in my pc, i dont have any version published in any site, if you need

thank you so much

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jooohhncommented, Aug 14, 2020

I couldn’t reproduce on v1.3.0. I think the issue is related to the ordering of your <Routes> in routes.tsx

This example will render HomePage instead of CustomerPage even if the given path is /customer. React-router’s Switch component renders the first child <Route> that matches the URL (basically /customer matches the path / first and renders HomePage)

<Switch>
  <Route path={routes.COUNTER} component={CounterPage} />
  <Route path={routes.HOME} component={HomePage} />
  <Route path={routes.CUSTOMER} component={CustomerPage} />
</Switch>

Problem should be fixed by ordering routes by COUNTER -> CUSTOMER -> HOME or using the exact property

0reactions
SingularityFcommented, Aug 14, 2020

I couldn’t reproduce on v1.3.0. I think may be related to the order of your <Routes> in routes.tsx

This example will render HomePage instead of CustomerPage even if the given path is /customer. React-router’s Switch component renders the first child <Route> that matches the URL (basically /customer matches the path / first and renders HomePage)

<Switch>
  <Route path={routes.COUNTER} component={CounterPage} />
  <Route path={routes.HOME} component={HomePage} />
  <Route path={routes.CUSTOMER} component={CustomerPage} />
</Switch>

If this is the case, the problem can be fixed by ordering routes by COUNTER -> CUSTOMER -> HOME or using the exact property

I was facing the same issue and adding exact worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug] scully.routes.json not updated correctly #336 - GitHub
Once created, the file isn't updated anymore with npm run scully if new routes are added. It's still correctly upd...
Read more >
How to put the routes.json into web app from Visual Studio ...
I'm developing a new site using Visual Studio, ASP.Net Core 3.1. The site will be set to use CI to deploy to Azure...
Read more >
Creating a static route with json file not working.
I am trying to route all Internet traffic from 192.168.1.118 through WAN1. I have the following json in-place on the controller but it...
Read more >
How to setup json-server to use custom id and route?
To do that, we will have to create another file routes.json and define our custom mapping as shown below. { "/api/v1/users/:appId/preferences": ...
Read more >
Minimal APIs quick reference - Microsoft Learn
When a web app is created with Visual Studio or dotnet new , a Properties/launchSettings.json file is created that specifies the ports 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