import Router from 'marbles/router';
import WizardComponent from './views/wizard';
import Dispatcher from './dispatcher';

var MainRouter = Router.createClass({
	routes: [
		{ path: '', handler: 'landingPage' },
		{ path: '/install/:install_id', handler: 'landingPage' }
	],

	willInitialize: function () {
		Dispatcher.register(this.handleEvent.bind(this));
	},

	beforeHandler: function (event) {
		Dispatcher.dispatch({
			name: 'LOAD_INSTALL',
			id: event.params[0].install_id || ''
		});
	},

	landingPage: function (params, opts, context) {
		var props = {
			dataStore: context.dataStore
		};
		context.render(WizardComponent, props);
	},

	handleEvent: function (event) {
		var installID;
		switch (event.name) {
			case 'INSTALL_EXISTS':
				installID = this.history.pathParams[0].install_id;
				if ( !event.exists && (!event.id || event.id === installID) ) {
					this.history.navigate('/');
				} else if (event.exists && installID !== event.id) {
					this.history.navigate('/install/'+ event.id);
				}
			break;

			case 'LAUNCH_INSTALL_SUCCESS':
				installID = event.res.id;
				this.history.navigate('/install/'+ installID);
			break;
		}
	}
});
export default MainRouter;

import Router from 'marbles/router';
import WizardComponent from './views/wizard';
import Dispatcher from './dispatcher';

var MainRouter = Router.createClass({
	routes: [
		{ path: '', handler: 'landingPage' },
		{ path: '/install/:install_id', handler: 'landingPage' }
	],

	willInitialize: function () {
		Dispatcher.register(this.handleEvent.bind(this));
	},

	beforeHandler: function (event) {
		Dispatcher.dispatch({
			name: 'LOAD_INSTALL',
			id: event.params[0].install_id || ''
		});
	},

	landingPage: function (params, opts, context) {
		var props = {
			dataStore: context.dataStore
		};
		context.render(WizardComponent, props);
	},

	handleEvent: function (event) {
		var installID;
		switch (event.name) {
			case 'INSTALL_EXISTS':
				installID = this.history.pathParams[0].install_id;
				if ( !event.exists && (!event.id || event.id === installID) ) {
					this.history.navigate('/', { replace: true });
				} else if (event.exists && installID !== event.id) {
					this.history.navigate('/install/'+ event.id, { replace: true });
				}
			break;

			case 'LAUNCH_INSTALL_SUCCESS':
				installID = event.res.id;
				this.history.navigate('/install/'+ installID, { replace: true });
			break;
		}
	}
});
export default MainRouter;

Use replaceState for updating the URL
installer: Use replaceState for updating the URL

Disables back button. The other option is to allow navigating between
steps using the browser's back/forward, but that overlaps with the
current behaviour of picking up an existing install process using the
base URL. This is a temporary fix and will be revisited soon.

refs #1337

Signed-off-by: Jesse Stuart <a5c95b3d7cb4d0ae05a15c79c79ab458dc2c8f9e@jessestuart.ca>
