老师,多个页面时怎么通过地址篮切换页面呢?
来源:4-1 目的地页的结构和样式
多盐少糖
2021-09-13 20:37:12
问题描述:
老师,完成首页之后制作目的地页的时候发现通过浏览器地址切换页面有问题,切换不到想要的页面,帮忙看下怎么才能正确通过修改地址栏来切换页面
webpack:
const path = require('path');
// 导入插件
const HtmlWebpackPlugin = require('html-webpack-plugin');
// 获取根目录方法
const resolve = dir => path.resolve(__dirname,dir);
module.exports={
mode:'development',
entry:{
index:'./src/pages/index',
destination:'./src/pages/destination'
},
output:{
path:resolve('dist'),
filename:'js/[name].js'
},
devtool: 'cheap-module-eval-source-map',
resolve:{
extensions: ['.js'],
// 路径别名
alias:{api: resolve('src/api'),
fonts: resolve('src/assets/fonts'),
icons:resolve('src/assets/icons'),
styles: resolve('src/assets/styles'),
components: resolve('src/components'),
pages: resolve('src/pages'),
utils: resolve('src/utils')
}
},
module:{
// css
rules:[{
test:/\.css$/,
use:['style-loader','css-loader']
},
// 图片
{
test:/\.(png|jpe?g|gif|svg)$/,
loader:'url-loader',
options:{
limit:1000,
name:'images/[name].[ext]',
esModule:false
}
},
// 字体
{
test: /\.(woff2?|eot|ttf|otf)$/,
loader: 'url-loader',
options: {
limit: 10000,
name: 'fonts/[name].[ext]'
}
},
// 模板
{
test:/\.art$/,
use:'art-template-loader'
}
]
},
plugins:[
// 克隆
new HtmlWebpackPlugin({
filenmae:'index.html',
template:'./src/pages/index/index.art',
chunks: ['index']
}),
new HtmlWebpackPlugin({
filenmae:'destination.html',
template:'./src/pages/destination/destination.art',
chunks: ['destination']
})
]
}
文件目录结构:
相关截图:
1回答
同学你好,http://localhost:8080/默认打开的就是index.html页面,如果要打开目的页的话,在http://localhost:8080/链接的后面拼上destination.html即可(即:http://localhost:8080/destination.html)
而同学的代码运行出现问题,是因为webpack.config.js文件中,filename拼写有误,如图
祝学习愉快!
相似问题