Comments (2)
The following snippet might be helpful to resolve non-root URLs:
let isUrlAvailable;
let urlDocument, urlBase, urlAnchor;
function ensureUrlAvailableOrPolyfilled() {
if (isUrlAvailable === undefined) {
try {
const url = new URL('b', 'http://a');
url.pathname = 'c';
isUrlAvailable = (url.href === 'http://a/c');
} catch (e) {
isUrlAvailable = false;
}
if (!isUrlAvailable) {
// The URL constructor is not available in IE11. Polyfil it by creating an
// HTMLAnchorElement in an in-memory HTML document.
urlDocument = document.implementation.createHTMLDocument('url');
urlBase = urlDocument.createElement('base');
urlDocument.head.appendChild(urlBase);
urlAnchor = urlDocument.createElement('a');
if (!urlAnchor.origin) {
// IE11: HTMLAnchorElement does not have the `origin` property
Object.defineProperty(urlAnchor, 'origin', {
get: () => {
// IE11: on HTTP and HTTPS the default port is not included into
// window.location.origin, so won't include it here either.
const port = urlAnchor.port;
const protocol = urlAnchor.protocol;
const defaultHttp = protocol === 'http:' && port === '80';
const defaultHttps = protocol === 'https:' && port === '443';
const host = (defaultHttp || defaultHttps)
? urlAnchor.hostname
: urlAnchor.host;
return `${protocol}//${host}`;
}
});
}
}
}
}
function resolveURL(path, base) {
ensureUrlAvailableOrPolyfilled();
if (isUrlAvailable) {
return new URL(path, base);
}
urlBase.href = base;
urlAnchor.href = path.replace(/ /g, '%20');
return urlAnchor;
}
from router.
Hey @vlukashov has this been added to the router?
If not, where should the code snippet above be added?
from router.
Related Issues (20)
- is it possible to treat `#` as a normal character (and not a "hash" prefix) on a route
- Wrong timing for scrolling to the top when handling click
- Add issue templates
- How to use a link checker like Lychee with Vaadin Router wildcards
- Include types in package.json
- Router.go should find a route based on its defined path relative to the base href
- Please support search and hash strings in commands.redirect() as well
- router-ignore broken
- Distribute as not bundled library
- Enable native View Transition API HOT 2
- Different route animation behaviour depending on from/to routes
- Version Conflict difference between assemble and build packages.json HOT 1
- Router.go not working properly
- URL fragment navigation not working
- Broken link on github page
- Handling Client Side Routing When Hosting Vaadin Lit project on AWS S3
- Whole Page Refresh
- Failed to construct 'CustomElement': The result must not have attributes HOT 2
- onBeforeEnter not called after page refresh
- Clear outlet content (and update related internal data) at start of handling a navigation event.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from router.