Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Base path #85

Closed
quentincaffeino opened this issue Jan 28, 2020 · 8 comments
Closed

Feature request: Base path #85

quentincaffeino opened this issue Jan 28, 2020 · 8 comments
Labels
enhancement New feature or request

Comments

@quentincaffeino
Copy link

For example for testing your web you might use git[la|hu]b/pages. And it will have repo name as a part of path in the address. Need configuration feature to specify base path.
Otherwise getting: Uncaught Error: Route could not be found. Make sure /front-old/.svelte or /front-old//index.svelte exists. A restart may be required.

@jakobrosenberg
Copy link
Member

This is something we've discussed internally and it's definitely something we want, even if it's not a high priority at the moment.

@jakobrosenberg jakobrosenberg added the enhancement New feature or request label Jan 28, 2020
@quentincaffeino
Copy link
Author

I looked a bit on the code and I might get it wrong, but isn't it essentially about adding base to each route in template generator?
Are there other essential parts besides tests, cli, initializer?

@jakobrosenberg
Copy link
Member

jakobrosenberg commented Jan 30, 2020

There are tests, (but you'd have to ask @rixo about those), SSR, prerendering and helpers.

I wonder if something like src/pages/routify would work. You'd have to update your HTML template though.

It's a bit hacky, but might work.

@jakobrosenberg
Copy link
Member

Been pondering this issue and I wonder if we can add anything that couldn't be accomplished by adjusting the file structure to src/pages/[basepath]. The entrypoint HTML template would have to be configured manually regardless of a config option (unless we start generating the index.html/__app.html entrypoint).

Pros

  • It follows the filestructure convention
  • It's easy to reason about
  • It's very easy to maintain

Cons

  • You have to know how deep your app is nested.

Alternatively we'd have to add an options for a custom path, but it would take some wiring to make it work with prerendering and ssr.

@wighawag
Copy link

Hey, did not try routify yet but it would be cool if routify support IPFS website that can be accessed from different path at the same time

Indeed, with IPFS a website can be accessed from a gateway via hash (with an ipfs/ prefix, like https://gateway.ipfs.io/ipfs/QmNVTWGZ4qoW4DwiTze3icNJKhKBArR4HrCR1sapAFaPYg/
Or through a domain name , like : https://wighawag.eth.link (without any prefix)

I made a PR on sapper that support it : sveltejs/sapper#866

It uses base path plus it ensure slash terminated path are supported so that it works on IPFS

@yus-ham
Copy link
Contributor

yus-ham commented Mar 19, 2020

I personally uses routify in my SPA app. I done changes to match this feature. but without SSR. you can find it here: https://github.com/sup-ham/routify/tree/base-url
I might do PR but currently have no time. thanks.

Here the usage

BASE_URL=/base SPA_ENTRY=__app.html npm run [ dev | build ]

the routify-starter's rollup.config.js needed to updated for replacing string {BASE_URL} in template.

Copying template part

	plugins: [
		copy({
			targets: [
				{ src: staticDir + '/argon', dest: distDir },
				{
					src: template,
					dest: distDir,
					rename: process.env.SPA_ENTRY ||'index.html',
					transform: (content) => content.toString().replace(/\{BASE_URL}/g, process.env.BASE_URL || ''),
				},
			], copyOnce: true
		}),

function serve() at bottom

function serve() {
	let started = false;

	return {
		writeBundle() {
			if (!started) {
				started = true;

				require('child_process').spawn('npm', ['run', 'start', '--', '--dev', process.env.SPA_ENTRY ||''], {
					stdio: ['ignore', 'inherit', 'inherit'],
					shell: true
				});
			}
		}
	};
}

@jakobrosenberg
Copy link
Member

Looks very interesting.

@jakobrosenberg
Copy link
Member

There's experimental basepaths in the beta build, but it might be replaced in favor of an URL transform function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants