brooks94
brooks94

Reputation: 3936

Dart project with more than one main HTML file

I'm using Dart to build some functionality for an intranet site, and I'm wondering what the best way to organize a project with two "pages" in it is. Questions like this one, suggest that the (only) way to do it is by dynamically generating the contents of the page based on some user action.

I don't like this idea for a couple of reasons. First, the dynamic generation logic/file organization breaks up the HTML and makes it harder for the designers to work on. Second, it's not immediately obvious how I map the two "versions" of the page onto different URLs. And it all just seems needlessly complex.

Is there a way simply to have two "HTML" pages in a single Dart project, that are served as distinct URLs, but can share code, etc. My naive attempt to simply add a new HTML file and put the Dart script links into it did not work (the templates did not get rendered).

Upvotes: 3

Views: 998

Answers (2)

Chris Buckett
Chris Buckett

Reputation: 14398

Mezoni's answer is correct, in that single-page applications will lose their state as you navigate from one page to another (typical methods to pass state between pages include using the url querystring, local storage or server-side session...).

However... I'm going to assume that you're using Web-UI to create your page (based upon the statement that "the templates did not get rendered"

Probably all you're missing is adding the second page to the build.dart file, used to produce the output html+script, for example:

import 'dart:io';
import 'package:web_ui/component_build.dart';

// Ref: http://www.dartlang.org/articles/dart-web-components/tools.html
main() {
  build(new Options().arguments, ['web/page1.html', 'web/page2.html']);
}

Both page1.html and page2.html can contain identical content, and point to the same underlying .dart libraries (but in the real world, I suspect you'd want different content).

Upvotes: 3

mezoni
mezoni

Reputation: 11210

The web applications that interacts with the user using client-side layer often written as one page application. This means that this kind of application is an application that store state on client-side.

When user leave this page (url) application lose its state. Also this will happen if you try to refresh the page. Different pages in this case means entry points to different instances of the application.

To write such applications, usually requiring the use of specific frameworks (to increase productivity).

Aplications that uses different pages for different actions may be called multiple-page applications. In this case global state of application stored not on the client side but on the server-side where this application located.

When the user goto from one page to another page the application is not closed immediately because it stores their state in special "session" instance which represent an application instance.

If your questions sounds like "Is there a way simply to have two" HTML "pages in a single Dart project" then answer may be as the following.

It depends on what you are using frameworks and how they (frameworks) organized.

As a general rule client application uses only one entry point into the application but this depends, as I say, on framework features and conventions.

And as I know the Dart is not an framework but programming language and platform for writing similar frameworks.

Upvotes: 1

Related Questions