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

loading doesn't work #4

Closed
sxcooler opened this issue Feb 21, 2017 · 7 comments
Closed

loading doesn't work #4

sxcooler opened this issue Feb 21, 2017 · 7 comments

Comments

@sxcooler
Copy link

sxcooler commented Feb 21, 2017

import { h, Component } from 'preact';
import { Router } from 'preact-router';
import AsyncRoute from 'preact-async-route';
import Header from './header';
import Home from './home';

export default class App extends Component {
	/** Gets fired when the route changes.
	 *	@param {Object} event		"change" event from [preact-router](http://git.io/preact-router)
	 *	@param {string} event.url	The newly routed URL
	 */
	handleRoute = e => {
		this.currentUrl = e.url;
	};

	getProfile(){
		return new Promise(resolve=>{
			setTimeout(()=>{
				System.import('./profile').then(module => {resolve(module.default);});
			},2000);
		});
	}

	render() {
		return (
			<div id="app">
				<Header />
				<Router onChange={this.handleRoute}>
					<Home path="/" />
					<AsyncRoute path="/profile" component={this.getProfile} />
					<AsyncRoute path="/profile/:user" component={this.getProfile}
								loading={()=>{return <span>loading...</span>}} />
				</Router>
			</div>
		);
	}
}

my code is based on https://github.com/developit/preact-boilerplate & this project's example, the async-route works well, but the loading does not show up.
after 2 sec the real content just come out.

@prateekbh
Copy link
Owner

@sxcooler can you re-produce this in an isolated repo/branch?

@sxcooler
Copy link
Author

@prateekbh ok, maybe later.

@prateekbh
Copy link
Owner

@sxcooler i tried running here
https://github.com/prateekbh/preact-async-route/tree/master/example

seems to be working

@prateekbh
Copy link
Owner

@sxcooler checked with preact-boilerplate
it is indeed showing up, just hidden under the fixed header 😛
give your span a padding-top of 56px and you shall see it 😆

@prateekbh
Copy link
Owner

@sxcooler feel free to re-open if i am wrong

@sxcooler
Copy link
Author

@prateekbh I didn't test correctly, sorry for the trouble.

@prateekbh
Copy link
Owner

no problem 😄
happy to help

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

No branches or pull requests

2 participants