问题描述
因此,我要使用新的Polymer应用程序要做的第一件事是将其部署到现有网站上的目录中.似乎唯一可行的方法是将其部署到根/
.
So the first thing I want to do with a new Polymer app is deploy to a directory on an existing website. The only thing that seems to work is deploying to root /
.
以商店"为例.我这样做:
Let's take the Shop example. I do:
-
polymer init
并选择商店 -
polymer build
-
Robocopy.exe .\build\bundled\ C:\inetpub\wwwroot\p\ /MIR
-
start http://localhost/p/
polymer init
and choose shoppolymer build
Robocopy.exe .\build\bundled\ C:\inetpub\wwwroot\p\ /MIR
start http://localhost/p/
您看到我在Windows上.我认为使用IIS是无关紧要的,因为我仅依靠服务器来提供静态内容.
You see I'm on Windows. I assume that using IIS is irrelevant, since I'm relying on the server just to serve static content.
我需要在shop模板中进行哪些编辑才能使其在URL http://localhost/p/
上起作用?
What do I need to edit in the shop template to make it work at the url http://localhost/p/
?
推荐答案
polymer-cli创建的应用带有从根级别"/"提供服务的假设.在生成的项目index.html
中,您将找到两个注释
The polymer-cli created apps came with assumption of serving from root level '/'. In generated project index.html
you will find two comments
<!--
The `<base>` tag below is present to support two advanced deployment options:
1) Differential serving. 2) Serving from a non-root path.
Instead of manually editing the `<base>` tag yourself, you should generally either:
a) Add a `basePath` property to the build configuration in your `polymer.json`.
b) Use the `--base-path` command-line option for `polymer build`.
Note: If you intend to serve from a non-root path, see [polymer-root-path] below.
-->
<base href="/">
<!-- ... -->
<script>
/**
* [polymer-root-path]
*
* By default, we set `Polymer.rootPath` to the server root path (`/`).
* Leave this line unchanged if you intend to serve your app from the root
* path (e.g., with URLs like `my.domain/` and `my.domain/view1`).
*
* If you intend to serve your app from a non-root path (e.g., with URLs
* like `my.domain/my-app/` and `my.domain/my-app/view1`), edit this line
* to indicate the path from which you'll be serving, including leading
* and trailing slashes (e.g., `/my-app/`).
*/
window.Polymer = {rootPath: '/'};
// ...
</script>
如果在此index.html
文件中您注释掉base
标记并设置window.Polymer rootPath
为类似'/0/polymer-test/build/es5-bundled/'
之类的东西,您将能够在http://localhost/0/polymer-test/build/es5-bundled/
if in this index.html
file you comment out base
tag and set window.Polymer rootPath
to something like '/0/polymer-test/build/es5-bundled/'
you will be able to navigate in app on http://localhost/0/polymer-test/build/es5-bundled/
这篇关于将Polymer App放到/root而不是根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!