PatrickJS-starter
PatrickJS-starter copied to clipboard
How to deal with multiple pages?
Here is my app looks like:
angular2-webpack-starter/
├──config/ * configuration
│
├──src/
| ├──main.browser.ts
│ │
| ├──index.html * Index.html: The main entry of the app,which visted by localhost:3000.
│ │
│ ├──admin/ * Admin module floder
│ │ └──index.thml * This file is Admin module entry,I wanna visit by localhost:3000/admin
│ └──assets/
│
├──tslint.json
├──typedoc.json
├──tsconfig.json
├──tsconfig.webpack.json
├──package.json
└──webpack.config.js
I wanna visit admin module by http://localhost:3000/admin , and Here is webpack configs:
//webpack.dev.js
devServer: {
port: METADATA.port,
host: METADATA.host,
historyApiFallback: {
rewrites: [
// rewrite url so I can visit localhost:3000/admin instead of localhost:3000/admin/index.html
{ from: /^\/admin/, to: '/admin/index.html' },
],
},
watchOptions: {
aggregateTimeout: 300,
poll: 1000
}
},
//webpack.common.js add a plugin for /admin/index.html
new HtmlWebpackPlugin({
template:'src/admin/index.html',
title: METADATA.title,
chunksSortMode: 'dependency',
metadata: METADATA,
inject: 'head',
}),
But actually the scripts and header tags not inject to /src/admin/index.html page,just some <% XXXX) { %> <% } %>syntax,so how to deal with this situation?
Thanks.
If your admin module is an NgModule you could add it to your app's routes. Look at the relationship between src/app/+detail/detail.module.ts and how it's loaded in src/app/app.routes.ts.
You'll need to create a path linking /admin with your module.
{ path: 'admin', loadChildren: './+admin#AdminModule'},