`#` gets replaced with `/` in url
See original GitHub issueI’m using choo and just found this really weird behavior, which looks like a bug.
When you open a url that contains a #
, it gets replaced with /
, which causes a route not to match. e.g. /test#foo
is transformed to /test/foo
I would have expected that /test#foo
matches the route /test
.
To fix the issue we could change the suffix
regex on line 10 to include the #
.
And btw, there’s no need to escape ?
in character sets.
@@ -7,7 +7,7 @@ var isLocalFile = (/file:\/\//.test(typeof window === 'object' &&
var electron = '^(file:\/\/|\/)(.*\.html?\/?)?'
var protocol = '^(http(s)?(:\/\/))?(www\.)?'
var domain = '[a-zA-Z0-9-_\.]+(:[0-9]{1,5})?(\/{1})?'
-var qs = '[\?].*$'
+var qs = '[?#].*$'
/* eslint-enable no-useless-escape */
var stripElectron = new RegExp(electron)
How to reproduce it
// launch with `bankai start ./test.js` and open https://localhost:8080/test#foo
const choo = require('choo')()
const html = require('bel')
choo.route('/test', function (state) {
return html`
<body>
This route does not match: /test#foo<br>
state.route: ${state.route}<br>
state.href: ${state.href}
</body>
`
})
choo.route('/test/foo', function (state) {
return html`
<body>
This route matches: /test#foo<br>
state.route: ${state.route}<br>
state.href: ${state.href}
</body>
`
})
choo.mount('body')
And sorry for writing on christmas 😆. I just got home and began coding 🤦♂️ .
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
The url get replaced by space character %20 - Stack Overflow
You can use urlencode to encode your url. The decoding will happen automatically, and can get the value from $_GET.
Read more >HTML URL Encoding Reference - W3Schools
Character From Windows‑1252 From UTF‑8
space %20 %20
! %21 %21
" %22 %22
Read more >Space in URL getting replaced by %20 - MSDN - Microsoft
Hi,. I am creating dyanamic hyperlinks in my application. E.g. ... and this link is getting replaced when shown on IE. ... I...
Read more >How to prevent plus sign from being replaced with space?
I have a URL that auto populates a form but every time there is a "+" as part of a text string populating...
Read more >location.replace() - Web APIs - MDN Web Docs
The replace() method of the Location interface replaces the current resource with the one at the provided URL. The difference from the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No problem, it just was very unexpected. I spent some time on it to figure out what happened. Thanks, the docs PR is how I found that functionality.
Yep, maybe with another match when the hash is present.
@marcbachmann heya, yeah sorry this isn’t working the way you’d hoped. The hash routing has always been a bit of a tricky one.
We merged our routing docs today. Could you perhaps take a look to see if the information you were missing now exists? That’d be a great help so that nobody runs into this in the future!
Separate from that, I do agree that having routes like
/foo/bar#baz
should work. Perhaps we could do some work on that too?Thanks heaps for the very detailed issue!