5

I set my base URL in axios.create() method and consume it another pages. but it added unnecessary '%E2%80%8B' in the URL. Is there any way to avoid this issue? This is my code block:

import axios from 'axios';

const apiVersion = 1;
export const baseURL = ('https://localhost:50001')

export default axios.create({
  baseURL: baseURL,
});

export const urls = {
    unit: {
    get_all: `/​api/v${apiVersion}/Unit/get-all-units`,
    get_by_key: `api/v${apiVersion}ion}/Unit/get-unit`,
    post: `/api/v${apiVersion}/Unit/save-unit`,
    put: `/api/v${apiVersion}/Unit/update-unit`,
    delete: `​/api​/v${apiVersion}​/Unit​/delete-unit​`
  }
}

This axios i intended to use my another component in this way:

const getAllUnits = async () => {
    try {
      await axios
        .get(urls.unit.get_all)
        .then(res => {
          setRecords(res.data.data);
          setIsLoaded(true)
        })
    } catch (e) {
      console.log(e);
    }
  }

But it showing this error. Please help me out.enter image description here

Nasir
  • 233
  • 2
  • 12
  • the base url should be `http://localhost:50001` instead of https – angelo Jan 31 '21 at 05:39
  • 2
    Seems like you have a [zero width space character](https://github.com/whatwg/url/issues/151) in your url. So, to fix it, you need to retype (not copy paste) the urls in the code. – Ajeet Shah Jan 31 '21 at 06:02
  • There are few editor extensions to see these characters. https://stackoverflow.com/a/56501961/2873538. Or try https://stackoverflow.com/q/11305797/2873538 – Ajeet Shah Jan 31 '21 at 06:08

1 Answers1

10

There's an invisible character in your template string(s), called "zero width space" (see this table). You may have accidentally inserted it or copied it from somewhere else. Try deleting and retyping the template strings entirely to make sure you get rid of it.

bradtreloar
  • 349
  • 2
  • 10
  • Thanks. i found my problem. but is there any solution? i have a lot of urls. to manually typing this is annoying – Nasir Jan 31 '21 at 06:01
  • You could try pasting your code into a simple text editor (like Notepad, if you're on Windows) and then paste it back into your code editor. You could also try doing a find-and-replace using your code editor: copy the start of the offending string ("`api", including the backtick), paste it into the "find" field, then type in "`api" in the "replace" field. – bradtreloar Jan 31 '21 at 06:08