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.

Error: Only absolute urls are supported

See original GitHub issue

Hello, i get this error when i am trying this:

 path: '/news',

  children: [
    {
      path: '/',
      action() {
        return {
          component: <Layout><News /></Layout>,
        };
      }
    },
    {*/
      path: '*',
      async action({ path, store }) {
        try {
          await store.dispatch(loadSelectedNews({ path }));
          debugger
          const data = store.getState().selectedNews;
          return {
            component: <Layout><Content content={data} /></Layout>,
          };
        } catch (e) {
          throw new Error(e);
        }
    },
 },]
};

Is this error because i am using dynamic path as nested of parent /news?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
frenzzycommented, Feb 7, 2017

Do you have import fetch from '../../core/fetch'; at the top of this file?

This module uses whatwg-fetch and node-fetch polyfills on client and server side respectively.

Protocol and hostname should be always specified in the url for node-fetch, and our isomorphic src/core/fetch module resolves this problem, just use it instead of whatwg-fetch/node-fetch or isomorphic-fetch.

1reaction
frenzzycommented, Feb 7, 2017

No, nested wildcard routes e.g. { path: ‘*’, … } should work fine. Playground: https://jsfiddle.net/frenzzy/220eq2sv/

But need to remember that path inside action method is relative to the parent route:

const routes = [
  {
    path: '/one',
    action({ path }) {
      console.log(path); // => /one
    },
  },
  {
    path: '/two',
    children: [
      {
        path: '/',
        action({ path }) {
          console.log(path); // => / (not /two/)
        },
      },
      {
        path: '/three',
        action({ path }) {
          console.log(path); // => /three (not /two/three)
        },
      },
    ],
  },
];

Also need to remember about url encoding:

// window.location.pathname or req.path in express example
const location = new URL('/café');
console.log(location.pathname); // => /caf%C3%A9

const routes = [
  {
    path: '*',
    action({ path, params }) {
      console.log(path); // => /caf%C3%A9
      console.log(params); // => {}
    },
  },
  {
    path: '/:any*',
    action({ path, params }) {
      console.log(path); // => /caf%C3%A9
      console.log(params); // => { any: 'café' }
    },
  },
];

And if you need the original url inside your action method, you can pass it down via router:

UniversalRouter.resolve(routes, {
  path: location.pathname, // or req.path for express
  originalUrl: location.pathname, // or req.path for express
});

const routes = { path: '/one', children: [
  { path: '/two', action({ path, originalUrl }) {
    console.log(path);        // => '/two'
    console.log(originalUrl); // => '/one/two'
  } },
] };

looks like in your example loadSelectedNews() throws an error, so need to exactly know what this function expects, can you provide an example?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js - Error: only absolute urls are supported
It means you are trying to export data and NextJS does not support fetching data from pages/api/* directory. To avoid errors, its better...
Read more >
Error: only absolute urls are supported · Issue #481
It looks like there's something wrong with the URL in the fetch method. For me, it solved by changing url in the fetch...
Read more >
TypeError Only absolute URLs are supported
It looks like it expects other environment variables (e.g. that contain the subscription key), as well.
Read more >
When trying to deploy to Vercel: TypeError: Only absolute ...
When trying to deploy to Vercel: TypeError: Only absolute URLs are supported : r/nextjs.
Read more >
Netlify Dev - TypeError: Only absolute URLs are supported
I am using Nuxt. For a new feature I need to start using Netlify functions. In order to run everything locally I started...
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