首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >preact异步路由器找不到块

preact异步路由器找不到块
EN

Stack Overflow用户
提问于 2017-03-10 16:00:23
回答 3查看 301关注 0票数 0

我对react.js (使用preact)非常陌生,并且遇到了异步路由(preact-异步路由器)的问题。

我的main.js:

代码语言:javascript
复制
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")
);

我的home.jsx:

代码语言:javascript
复制
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>;
    }
}

我的hello.jsx:

代码语言:javascript
复制
import {h, render, Component} from 'preact';

/** @jsx h */

export default class Hello extends Component {
    render() {
        return <h1>Hello {this.props.matches.foo}!</h1>
    }
}

Webpack创建了bundle.js和1.bundle.js ( hello.jsx)!

所有在我的资源-dir(资源-dir是通过express.static可用)。

加载了home.jsx,链接指向(localhost/hello/Earth)。

现在的问题是1.bundle.js没有加载!浏览器(bundle.js)在"/hello/1.bundle.js“下而不是在"/resources/1.bundle.js”下请求文件!

我怎么才能解决呢?

编辑:

现在起作用了。在我的webpack配置中添加"publicPath“和"/resources/”。谢谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-03-10 18:13:36

@Kian --似乎您需要在webpack的配置中将output.publicPath设置为"/“。

票数 1
EN

Stack Overflow用户

发布于 2017-03-11 02:56:58

正如Jason所说,要确保输出中有这个publicPath,publicPath指导必须从哪些块中选择这些块。

票数 1
EN

Stack Overflow用户

发布于 2018-06-07 12:56:23

还可以在文件名中指定名称(如果希望publicPath保留/):

代码语言:javascript
复制
output: {
    filename: './dist/[name].bundle.js'
},

那么所有js包文件都将位于dist目录中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42722658

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档