Repository: next.js
Issue: Links at basePath not working for random internal links
Labels: bug

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000
    Binaries:
      Node: 19.4.0
      npm: 9.2.0
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.2.3
      eslint-config-next: 13.0.6
      react: 18.2.0
      react-dom: 18.2.0
```


### Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Data fetching (gS(S)P, getInitialProps), Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)

### Link to the code that reproduces this issue

https://github.com/hahnbeelee/mint/tree/0e8c9c3b147d18ab1847610baecd441ccb98403b

### To Reproduce

1. Clone the above repo
2. check out to the commit
3. `cd client`
4. Run `yarn && yarn preconfigure && yarn dev`
5. Click on Lists from the navigation
![CleanShot 2023-03-01 at 10 33 24@2x](https://user-images.githubusercontent.com/55263191/222233124-2bf8e893-56f8-44ad-bc46-076f012e4562.png)

Notice it redirects to the homepage. This happens when a page doesn't exist. However we do know it exists because if you directly navigate to http://localhost:3000/docs/writing-content/list it shows us the page. 

(ignore the hydration errors)

https://user-images.githubusercontent.com/55263191/222250717-12370d71-ac71-451a-812b-3c5c8f0ad8bc.mp4

### Describe the Bug

Certain links are not directing properly. In the above example, the link http://localhost:3000/docs/writing-content/list exists, but when I navigate to it through the nav bar it doesn't direct to it. (We programmed it so that links that don't exist redirect to the home page, so if you try m)

This bug was introduced in next.js versions 13.2.1 or greater so we reverted back to 13.2.0. But even in [production](https://mintlify.com/docs/quickstart) (using next@13.2.0) you can see weird behavior when you click on all the other pages then click on "Writing Content/Lists" it redirects properly but you can see it kind of jumps to the top/takes a millisecond longer to load than other pages.

We noticed this only happens when a basePath is set.

We also found this in the Networks tab in inspect element:
```
Request URL: https://react.email/docs/docs/components/hr
Request Method: GET
Status Code: 308
```
The request URL has the basePath incorrectly prepended twice.

When we were at a next.js version >13.2.0 we noticed the redirect was not happening properly when navigating to the following paths from the side navigation:
https://react.email/docs/components/hr
https://www.relate.so/docs/wiki/SaaS/MRR
https://chainpatrol.io/docs/general/discord-bot
https://chainpatrol.io/docs/external-api/asset-list

we do not see any pattern with the urls so we're not sure what's triggering this behavior to happen at these specific links (other links work fine).

### Expected Behavior

Navigate properly to the page when clicking on an internal link from another page instead of redirecting.

### Which browser are you using? (if relevant)

Google Chrome

### How are you deploying your application? (if relevant)

Vercel