React router parameter and requests do not work

Since the last couple of days, I have found a solution to this problem. What happens here, I want a dynamic link. Here you can see below:

<Route path="/edit/:username" component={EditExpensePage} />

But when I go to /edit/12, I get this error:

GET http://127.0.0.1:8080/edit/bundle.js net :: ERR_ABORTED

Here is my code:

import React from 'react';
import { BrowserRouter, Route, Switch, Link, NavLink } from 'react-router-dom';
import ExpenseDashboardPage from '../components/ExpenseDashboardPage';
import AddExpensePage from '../components/AddExpensePage';
import EditExpensePage from '../components/EditExpensePage';
import HelpPage from '../components/HelpPage';
import NotFoundPage from '../components/NotFoundPage';
import Header from '../components/Header';

const AppRouter = () => (
  <BrowserRouter>
    <div>
      <Header />

        <Route path="/" component={ExpenseDashboardPage} exact={true} />
        <Route path="/create" component={AddExpensePage} />
        <Route path="/edit/:username" component={EditExpensePage} />
        <Route path="/help" component={HelpPage} />

    </div>
  </BrowserRouter>
);

export default AppRouter;
+4
source share
1 answer

It looks like you are uploading your file bundle.jswith a relative url.

Therefore, when you load a page http://127.0.0.1/Home(or something else), it resolves like http://127.0.0.1/bundle.jsthat which is correct.

However, when the page loads, http://127.0.0.1/edit/12it is resolved as http://127.0.0.1/edit/bundle.js, which is incorrect.

<script URL.

0

Source: https://habr.com/ru/post/1691477/


All Articles