Javascript 前置异步路由器不';找不到块
我不太熟悉react.js(使用preact)并遇到异步路由(preact-async-router)问题 My main.js:Javascript 前置异步路由器不';找不到块,javascript,node.js,asynchronous,preact,Javascript,Node.js,Asynchronous,Preact,我不太熟悉react.js(使用preact)并遇到异步路由(preact-async-router)问题 My main.js: import { h, render } from 'preact'; import {Router, Route} from 'preact-router'; import AsyncRoute from 'preact-async-route'; import Home from './components/home.jsx'; /** @jsx h */
import { h, render } from 'preact';
import {Router, Route} from 'preact-router';
import AsyncRoute from 'preact-async-route';
import Home from './components/home.jsx';
/** @jsx h */
function getHelloWorld(){
return System.import('./components/hello.jsx').then(module => module.default);
}
render(
<Router>
<Route path="/" component={Home} />
<AsyncRoute path="/hello/:foo" component={getHelloWorld}
loading={()=>{alert("loading...");}} />
</Router>
, document.getElementById("app")
);
从'preact'导入{h,render};
从'preact Router'导入{Router,Route};
从“预作用异步路由”导入异步路由;
从“./components/Home.jsx”导入Home;
/**@jsx h*/
函数getHelloWorld(){
返回System.import('./components/hello.jsx')。然后(module=>module.default);
}
渲染(
{警报(“加载…”);}}/>
,document.getElementById(“应用程序”)
);
My home.jsx:
import {h, Component} from 'preact';
import {Link} from 'preact-router';
/** @jsx h */
export default class Home extends Component {
render() {
return <h1>
This is home page<br/>
<Link href='/hello/Earth'>Earth</Link>
</h1>;
}
}
从'preact'导入{h,Component};
从“预作用路由器”导入{Link};
/**@jsx h*/
导出默认类Home extends组件{
render(){
返回
这是主页
土
;
}
}
My hello.jsx:
import {h, render, Component} from 'preact';
/** @jsx h */
export default class Hello extends Component {
render() {
return <h1>Hello {this.props.matches.foo}!</h1>
}
}
从'preact'导入{h,render,Component};
/**@jsx h*/
导出默认类Hello扩展组件{
render(){
返回Hello{this.props.matches.foo}!
}
}
Webpack创建bundle.js和1.bundle.js(用于hello.jsx)
全部在我的资源目录中(资源目录通过express.static提供)
home.jsx已加载,链接指向(localhost/hello/Earth)
现在的问题是1.bundle.js没有被加载!
浏览器(bundle.js)正在请求“/hello/1.bundle.js”下的文件,而不是“/resources/1.bundle.js”下的文件
我怎样才能解决这个问题
编辑:
现在可以了。将带有“/resources/”的“publicPath”添加到我的网页配置中。谢谢大家! @Kian-似乎需要在网页包配置中将output.publicPath设置为“/”。@Kian-似乎需要在网页包配置中将output.publicPath设置为“/”。正如Jason所说,请确保输出中有此publicPath,
publicPath
指示必须从何处拾取这些块
正如Jason所说,请注意输出中有这个publicPath,
publicPath
指示必须从何处拾取这些块
您还可以在文件名中指定[名称](如果希望publicPath保留/):
然后所有js捆绑包文件都将位于dist目录中您还可以在filename中指定[name](如果您希望publicPath保留/): 然后所有js包文件都将位于dist目录中
output: {
filename: './dist/[name].bundle.js'
},