sveltejs / template

Template for building basic applications with Svelte

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error on routes?

MrAmericanMike opened this issue · comments

Sorry if this is not an issue with the template itself and it's a problem coming from a total different place.

Whenever I run npm run build and then open the index.html on the public folder, for example with Live Server Extension on VSCode or upload the contents to a server, I get errors about scripts not found or type mismatch.

However after updating the routes in the index.html to have a . in front of the / everything works as expected.

So this:

	<link rel='icon' type='image/png' href='/favicon.png'>
	<link rel='stylesheet' href='/global.css'>
	<link rel='stylesheet' href='/build/bundle.css'>

	<script defer src='/build/bundle.js'></script>

Turned into:

	<link rel='icon' type='image/png' href='./favicon.png'>
	<link rel='stylesheet' href='./global.css'>
	<link rel='stylesheet' href='./build/bundle.css'>

	<script defer src='./build/bundle.js'></script>

Makes everything work (hopefully) as expected.

Is this something that needs updated, or the issue is somewhere else?

If you're opening index.html in a browser from the filesystem, then yes, none of these links will work. The intention is that you run this from a webserver with the public directory as the webroot (which is what the included npm scripts do).

This is the default in the template, rather than using relative paths, so that SPAs work. If you load the site at /some/deep/page and this returns the root index.html, then there can't be the same relative paths to the various built assets - and so we use absolute paths.