mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 12:27:16 +03:00
feat(examples): add navigation example (#1690)
This commit is contained in:
parent
8845487f9d
commit
26c6a832bf
@ -14,6 +14,7 @@ members = [
|
||||
"examples/commands/src-tauri",
|
||||
"examples/splashscreen/src-tauri/",
|
||||
"examples/state/src-tauri/",
|
||||
"examples/navigation/src-tauri/",
|
||||
# used to build updater artifacts
|
||||
"examples/updater/src-tauri",
|
||||
]
|
||||
|
@ -7,14 +7,8 @@
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
#[tauri::command]
|
||||
fn my_custom_command(argument: String) {
|
||||
println!("{}", argument);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![my_custom_command])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
7
examples/navigation/package.json
Normal file
7
examples/navigation/package.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "navigation",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"tauri": "node ../../tooling/cli.js/bin/tauri"
|
||||
}
|
||||
}
|
23
examples/navigation/public/index.html
Normal file
23
examples/navigation/public/index.html
Normal file
@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Tauri</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>index.html</h1>
|
||||
<select id="route">
|
||||
<option value="secondary.html">secondary.html</option>
|
||||
<option value="nested/index.html">nested/index.html</option>
|
||||
<option value="nested/secondary.html">nested/secondary.html</option>
|
||||
</select>
|
||||
<button id="go">Go</button>
|
||||
<a id="link" href="secondary.html">Go</a>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
10
examples/navigation/public/index.js
Normal file
10
examples/navigation/public/index.js
Normal file
@ -0,0 +1,10 @@
|
||||
const routeSelect = document.querySelector('#route')
|
||||
const link = document.querySelector('#link')
|
||||
|
||||
routeSelect.addEventListener('change', (event) => {
|
||||
link.href = event.target.value
|
||||
})
|
||||
|
||||
document.querySelector('#go').addEventListener('click', () => {
|
||||
window.location.href = (window.location.origin + '/' + routeSelect.value)
|
||||
})
|
17
examples/navigation/public/nested/index.html
Normal file
17
examples/navigation/public/nested/index.html
Normal file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Tauri</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1></h1>
|
||||
<button onclick="window.history.back()">Back</button>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
1
examples/navigation/public/nested/index.js
Normal file
1
examples/navigation/public/nested/index.js
Normal file
@ -0,0 +1 @@
|
||||
document.querySelector('h1').innerHTML = 'nested/index.html'
|
17
examples/navigation/public/nested/secondary.html
Normal file
17
examples/navigation/public/nested/secondary.html
Normal file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Tauri</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1></h1>
|
||||
<button onclick="window.history.back()">Back</button>
|
||||
<script src="secondary.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
1
examples/navigation/public/nested/secondary.js
Normal file
1
examples/navigation/public/nested/secondary.js
Normal file
@ -0,0 +1 @@
|
||||
document.querySelector('h1').innerHTML = 'nested/secondary.html'
|
17
examples/navigation/public/secondary.html
Normal file
17
examples/navigation/public/secondary.html
Normal file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Tauri</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1></h1>
|
||||
<button onclick="window.history.back()">Back</button>
|
||||
<script src="secondary.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
1
examples/navigation/public/secondary.js
Normal file
1
examples/navigation/public/secondary.js
Normal file
@ -0,0 +1 @@
|
||||
document.querySelector('h1').innerHTML = 'secondary.html'
|
10
examples/navigation/src-tauri/.gitignore
vendored
Normal file
10
examples/navigation/src-tauri/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
WixTools
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
config.json
|
||||
bundle.json
|
1
examples/navigation/src-tauri/.license_template
Normal file
1
examples/navigation/src-tauri/.license_template
Normal file
@ -0,0 +1 @@
|
||||
../../../.license_template
|
17
examples/navigation/src-tauri/Cargo.toml
Normal file
17
examples/navigation/src-tauri/Cargo.toml
Normal file
@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "navigation"
|
||||
version = "0.1.0"
|
||||
description = "A very simple Tauri Appplication with navigation"
|
||||
edition = "2018"
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { path = "../../../core/tauri-build", features = [ "codegen" ] }
|
||||
|
||||
[dependencies]
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = [ "derive" ] }
|
||||
tauri = { path = "../../../core/tauri", features = ["api-all"] }
|
||||
|
||||
[features]
|
||||
default = [ "custom-protocol" ]
|
||||
custom-protocol = [ "tauri/custom-protocol" ]
|
14
examples/navigation/src-tauri/build.rs
Normal file
14
examples/navigation/src-tauri/build.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use tauri_build::{try_build, Attributes, WindowsAttributes};
|
||||
|
||||
fn main() {
|
||||
if let Err(error) = try_build(
|
||||
Attributes::new()
|
||||
.windows_attributes(WindowsAttributes::new().window_icon_path("../../.icons/icon.ico")),
|
||||
) {
|
||||
panic!("error found during tauri-build: {}", error);
|
||||
}
|
||||
}
|
14
examples/navigation/src-tauri/src/main.rs
Normal file
14
examples/navigation/src-tauri/src/main.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#![cfg_attr(
|
||||
all(not(debug_assertions), target_os = "windows"),
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
56
examples/navigation/src-tauri/tauri.conf.json
Normal file
56
examples/navigation/src-tauri/tauri.conf.json
Normal file
@ -0,0 +1,56 @@
|
||||
{
|
||||
"build": {
|
||||
"distDir": "../public",
|
||||
"devPath": "../public",
|
||||
"beforeDevCommand": "",
|
||||
"beforeBuildCommand": ""
|
||||
},
|
||||
"tauri": {
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"identifier": "com.tauri.dev",
|
||||
"icon": [
|
||||
"../../.icons/32x32.png",
|
||||
"../../.icons/128x128.png",
|
||||
"../../.icons/128x128@2x.png",
|
||||
"../../.icons/icon.icns",
|
||||
"../../.icons/icon.ico"
|
||||
],
|
||||
"resources": [],
|
||||
"externalBin": [],
|
||||
"copyright": "",
|
||||
"category": "DeveloperTool",
|
||||
"shortDescription": "",
|
||||
"longDescription": "",
|
||||
"deb": {
|
||||
"depends": [],
|
||||
"useBootstrapper": false
|
||||
},
|
||||
"macOS": {
|
||||
"frameworks": [],
|
||||
"minimumSystemVersion": "",
|
||||
"useBootstrapper": false,
|
||||
"exceptionDomain": ""
|
||||
}
|
||||
},
|
||||
"allowlist": {
|
||||
"all": true
|
||||
},
|
||||
"windows": [
|
||||
{
|
||||
"title": "Welcome to Tauri!",
|
||||
"width": 800,
|
||||
"height": 600,
|
||||
"resizable": true,
|
||||
"fullscreen": false
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src blob: data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'"
|
||||
},
|
||||
"updater": {
|
||||
"active": false
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user