1

I am working with an Aurelia app that should start at a different page than index.html, but I cannot find where to change that.

Where in an Aurelia app can you set which landing page to use?

Jesse
  • 3,522
  • 6
  • 25
  • 40
Norm Strassner
  • 225
  • 3
  • 11

2 Answers2

3

This is misunderstanding. index.html page is the default landing page set by web server, not Aurelia. E.g. if you try to get the url e.g.https://stackoverflow.com the web server will give index.html by default. You need to change it in web server.

e.g. using Apache web server directive DirectoryIndex myindex.html

From https://httpd.apache.org/docs/2.4/mod/mod_dir.html:

The DirectoryIndex directive sets the list of resources to look for, when the client requests an index of the directory by specifying a / at the end of the directory name.

When using development server of Aurelia (default webpack-dev-server configured by aurelia-cli), the index.ejs compiles to index.html. You may need to change configuration of HtmlWebpackPlugin in webpack.config.js in order to change generated file from index.html to some other name:

 new HtmlWebpackPlugin({
  template: 'index.ejs',
  filename: 'myindex.html',
  ...
Community
  • 1
  • 1
Tomas Kulhanek
  • 867
  • 1
  • 10
  • 18
0

If you're using the CLI, there is not an easy way to do this. The CLI is mostly for basic use cases, and if you're trying to do something fancy, you're going to have to learn a bit more about JavaScript tooling.

You can still do it and here's how:

Open aurelia_project/tasks/run.js and make sure the server property of the argument to the browserSync function has the index property pointing at the index file you want to use, like this:

let serve = gulp.series(
  build,
  done => {
    browserSync({
      online: false,
      open: false,
      port: 9000,
      logLevel: 'silent',
      server: {
        index: 'my-special-index.html', // Make sure you have this line in there.
        baseDir: [project.platform.baseDir],
        middleware: [historyApiFallback(), function(req, res, next) {
          res.setHeader('Access-Control-Allow-Origin', '*');
          next();
        }]
      }
    }
);
Matthew James Davis
  • 12,134
  • 7
  • 61
  • 90
  • That seems like a pretty easy way, why would you say there's _no easy way to do this_? – Jesse Aug 29 '18 at 08:09
  • I've just tried this method, but whenever I visit `localhost:9000` it still points to the `index.html` file – Jesse Aug 29 '18 at 08:14
  • That seems easy but it didn't work. If you want it to work, it's not so easy. There's a way to get it done using this method, but like I said, you can't just copy paste my answer, you gotta pay attention to what is being logged in your console, make sure that you're modifying the correct configuration, etc. It's not easy. – Matthew James Davis Sep 13 '18 at 06:13